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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -