I have a collection as follows,

i want to query and populate only reviews which has the fromUser userID '233232'
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?
Schema
module.exports = function () {
var model = null;
var modelName = '_purchase';
try {
model = dbService.getModel(modelName);
} catch (error) {
var userSchema = dbService.createEntityDef({
userId: {
type: String
},
urlPicture: {
type: String
}
});
var reviewSchema = dbService.createEntityDef({
fromUser: userSchema,
toUser: userSchema,
rating: {
type: Number
},
comment: {
type: String
}
})
var purchaseSchema = {
_id: {
type: dbService.getPrimaryKeyType(),
index: true
},
purchaseId: {
type: String
},
reviews: [reviewSchema]
};
model = dbService.createModel(modelName, purchaseSchema, {
name: 'text'
}, modelName);
}
return model;
};
Your matchedCond
{ fromUser.userid : "youruserid" }
Your projCond
{ document: "$$ROOT" }
will return the objects with all properties.