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

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -