Thursday 27 April 2017

How to query and populate subdocuments only inside a document?

I have a collection as follows, enter image description here

i want to query and populate only reviews which has the userId '233232' inside fromUser.

Right now my helper class is as follows,

 queryaggregateWithProject: function (model, matchedCond, prjCond) {
            return new Promise(function (resolve, reject) {
                model.aggregate([
                    {$match: matchedCond},
                    {$project: prjCond}
                ], function (error, data) {
                    if (error)
                        reject(error);
                    resolve(data);
                });
            })
        }

what should i pass for matchedCond and projCond?



via face turn

No comments:

Post a Comment