You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think mongoose find function is very good, it can Cat.find({name:"leon"}).populate("path").sort({"field": - 1}).skip (0).limit (10).lean(); this chain call is very easy to use, but now I have a problem. I want to encapsulate the find function myself. How can I encapsulate it? I don't know how to encapsulate it. I know return this is a good idea, but what should I return here? I want someone to give me some ideas? Thank you for your help.
This is my code now. What should I do next. How can I write it?
asyncfind(options: Object,populate?: string){if(!populate){returnawaitthis.mappingModel(meta.collections).find(options);}if(typeofpopulate==="string"&&populate!==""){returnawaitthis.mappingModel(meta.collections).find(options).populate(populate);}throwError("Multi level chained calls are not supported ");// TODO 2020/11/27 15:09 How to realize multi level chain call}
The text was updated successfully, but these errors were encountered:
It's a good idea to encapsulate 3rd-party code with your own code, it helps with testing, and makes things easier if you want to change libraries in the future.
Assuming this.mappingModel(meta.collections) returns a mongoose model, you could do the following.
Notice how the code doesn't do any checks for whether populate/skip/limit/sort are present or not, because mongoose is smart enough to ignore the .populate if it's passed an empty value, same goes for the rest of the chain.
I am not sure what you mean by "multi level chain call", can you elaborate on that?
AbdelrahmanHafez
added
the
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
label
Nov 28, 2020
I think mongoose
find
function is very good, it canCat.find({name:"leon"}).populate("path").sort({"field": - 1}).skip (0).limit (10).lean();
this chain call is very easy to use, but now I have a problem. I want to encapsulate the find function myself. How can I encapsulate it? I don't know how to encapsulate it. I knowreturn this
is a good idea, but what should I return here? I want someone to give me some ideas? Thank you for your help.This is my code now. What should I do next. How can I write it?
The text was updated successfully, but these errors were encountered: