node.js - Mongoose aggregate method does not work -


i have these lines :

            score.find({gameid : gameid}).exec(function(err,obj){                 console.log("find length : " + obj.length);             });              score.aggregate([                 {$match: {gameid: gameid}}             ], function (err, result) {                 console.log('result : ' + json.stringify(result));                 console.log('is there error : ' + err);             }); 

and output of these lines

result : [] there error : null find length : 1 

i not understand, why "match" method of aggregate not work expected - finding documents, match properties. added score.find same "body" find out, if document exist , does.

ps : {gameid: gameid} - first gameid name of property, second 1 string value id looking for.


ps2: fluent api having same result :

            score.aggregate().match({gameid: gameid}).exec(function (err, result){                 console.log('result : ' + json.stringify(result));                 console.log('is there error : ' + err);             }); 

you should convert gameid string mongodb objectid

in mongoose

mongoose.types.objectid(gameid)

mongodb native way

new objectid(gameid)


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -