Monday, 15 March 2010

javascript - Mongodb findOne has no result / throws TypeError -



javascript - Mongodb findOne has no result / throws TypeError -

i'm new node/js/mongo bear me if have totally wrong.

i have local db.js file uses callbacks give me context on mongodb collection object. object valid , calling find() callback returns cursor var cursor expected. however, next phone call findone returns null both err , res.

if phone call findone in similar manner find, node throws typeerror complaining haven't passed in callback findone.

db.opendb( function(err, db) { if(err) { console.log(err); } else { var cursor = db.find(); console.log(cursor); db.findone({}, function(err, res) { console.log(res); }); } });

edit: db.js @johnnyhk notice i'm opening collection queue twice i'm still lost, have look.

try calling cursor.each() , see if there in cursor. seek commenting out conn.close(); in opendb function. think closing connection before data.

also seek

db = new mongodb.db('test', server, {w:1}),

instead of 'queue' if using default database.

javascript node.js mongodb

No comments:

Post a Comment