node.js - Mongoose grouping error -


i got trouble filter , group on mongodb. didn't undertanded how works.

for example, in query:

room.aggregate( [{     "$where": { "roomid" : myidhere },     "$group": {         "_id": '$mobileuser.gendertype',         "gendertypecount": {             "$sum": 1         }     } }] 

room model:

var roommodelschema = mongoose.schema({     roomid: string,     mobileuser: {         facebookid: string,         email: string,         name: string,         photourl: string,         gendertype: string,         birthday: date,         city: string         },     insertdate: date }) 

what should filter roomid , group gendertype?

use $match instead of $where, , put each pipeline operation own object:

room.aggregate([     { "$match": { "roomid" : myidhere } },     { "$group": {         "_id": '$mobileuser.gendertype',         "gendertypecount": {             "$sum": 1         }     }} ], function(err, result) {...}) 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -