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
Post a Comment