node.js - bluebird + mongoose error: "Can't use $__ with Array." -


i trying use bluebird + mongoose query devhiin instances each club respectively following code:

the data structure of devhiin.clubs is:

  , clubs  : [{ type: schema.types.objectid, ref: 'club' }]  

and club_m instance of club schema:

  user.findone({"_id": req.user._id})     .populate('clubs', '-textindex')     .exec(function (err, user) {     if (err) res.status(500).json(err);      if (user.clubs) {       var clubs_m = user.clubs;       (c = 0; c < clubs_m.length; c++) {         var club_m = clubs_m[c];          if (club_m.lst > lstdate) {            serverdata.clubs.push(club_m);            var ciinpromise = devhiin.find({"clubs": {$elemmatch: club_m}, "ts": {"$gt": lastsynctime}})             .populate('uid', '_id username', null, null)        // necessary user info hiin             .lean()             .sort("ts")             .limit(10)             .execasync();           promises.push(ciinpromise);         }       }        promise.all(promises).then(function (ciinarrays) {         serverdata.ciinarrays = ciinarrays;         callback(ciinarrays);        }).catch(function (err) {         callback(err);       }); 

unfortunately, got following error info:

"error: can't use $__ array. @ schemaarray.castforquery (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/lib/schema/array.js:188:13) @ schemaarray.cast$elemmatch (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/lib/schema/array.js:336:23) @ schemaarray.castforquery (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/lib/schema/array.js:191:19) @ module.exports (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/lib/cast.js:196:39) @ query.cast (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/lib/query.js:2350:10) @ query.find (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/lib/query.js:999:10) @ query.exec (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/lib/query.js:1984:17) @ query.trycatcher (/users/vince-fan/workspaces/mean/v_starter/node_modules/bluebird/js/main/util.js:24:31) @ query.ret [as execasync] (eval @ <anonymous> (/users/vince-fan/workspaces/mean/v_starter/node_modules/bluebird/js/main/promisify.js:1:0), <anonymous>:12:23) @ eventemitter.<anonymous> (/users/vince-fan/workspaces/mean/v_starter/controllers/sync.js:189:18) @ eventemitter.<anonymous> (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/node_modules/mpromise/lib/promise.js:175:45) @ emitone (events.js:77:13) @ eventemitter.emit (events.js:169:7) @ promise.safeemit (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/node_modules/mpromise/lib/promise.js:81:21) @ promise.fulfill (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/node_modules/mpromise/lib/promise.js:94:24) @ promise.resolve (/users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/lib/promise.js:113:23) @ /users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/lib/query.js:1174:16 @ /users/vince-fan/workspaces/mean/v_starter/node_modules/mongoose/node_modules/kareem/index.js:109:16 @ dontcallback0 (node.js:408:9) @ process._tickcallback (node.js:337:13)" 

is bluebird promise error, or mongoose error? how can fix it?

from code looks trying query using $elemmatch on array value specified query criteria expression. believe need use $in instead, selects documents value of clubs field equals value in specified array, stored variable club_m in case. query should this:

var ciinpromise = devhiin.find({"clubs": {"$in": [club_m._id]}, "ts": {"$gt": lastsynctime}}) 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -