node.js - Using aggregate with populate -
i trying use aggregate populate. need $group variable of referenced objectid schema. structure like:
var jobfilter = mongoose.schema({ location : { type: schema.types.objectid, ref: 'location' }, field : {type: schema.types.objectid, ref: 'jobfield'} }) var locationschema = mongoose.schema({ city : string, longitude : number, latitude : number });
and want group _field , city. wrote query did not work because of city. possible populate location somehow in query?
jobfilter.aggregate( [ { $match : { "jobfilter.field" : {$ne: null}, "jobfilter.location" : {$ne: null}} }, { $group : { _id: { "field" : "$jobfilter.field" , "location" : "$jobfilter.location.city" }, count: { $sum: 1}}}, { $sort : { count : -1} } ] ) .exec()
Comments
Post a Comment