Monday, 15 August 2011

node.js - Mongodb find(), limit(), sort() are not working -



node.js - Mongodb find(), limit(), sort() are not working -

in project need find recent document in collection. created 1 dose not homecoming , don't problem exactly. can help me? function:

dbmanagerconnection.prototype.finddevicelastdeviceactivity = function(id, callback){ database.deviceactivity.find({deviceid:id}).sort({devicelogin:-1}).limit(1), function(err, deviceid){ if(err || !deviceid){ console.log(err); callback(err, null); }else{ console.log("find: " + deviceid); callback(null, deviceid); } } }

update: yup yup solved problem show bellow:

dbmanagerconnection.prototype.finddevicelastdeviceactivity = function(id, callback){ database.deviceactivity.find({deviceid:id}).sort({devicelogin:-1}).limit(1).toarray(function(err, deviceid){ if(err || !deviceid){ console.log(err); callback(err, null); }else{ deviceid.foreach(function(item){ console.log("find: "); console.dir(item); }); callback(null, deviceid); } }); }

i welcome suggestions improve function.

node.js mongodb mongojs

No comments:

Post a Comment