javascript - Automatically populate() on Mongoose document fetch -
Is it possible to automatically run populated () for sub-documents referenced for a particular model?
I have a city model which refers to the area and country documents, which are brought to a city / city when I would like to automatically populate.
Well, for this there are no Docs in the Mongoose website; What I do, is something like this:
schema.statics.createQuery = function (populat) {var query = this.find (); Populates.forEach (function (p) {query.populate (p);}); Return query; }; Of course, this method has verification and some other stuff, but essentially what do I do with my model.
In your case, you can work hard to populate in such a method, if you need them strictly in each similar call.
Comments
Post a Comment