0

I am retrieving a document from MongoDB using find() in Node.js, while printing the result I am not getting the retrieved values. Here my code..

       db.collection("Product").find({'entry_id':entryID},function(err, result) {
        console.log("Output:",result);
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Jayanth
  • 485
  • 3
  • 9
  • 17
  • What are the retrieved values? Are you sure your query is correct? If mongodb finds no matching documents it wont give you an error, it will just give you a `null` result – jtmarmon Jan 05 '15 at 07:33

1 Answers1

1

You could just about place money on entry_id is an ObjectId value and what you are passing as a variable is actually just a string.

But the other obvious thing is that you are using .find() in the wrong way. The "result" returned is a "cursor". If you want something that looks like a whole result set, then use .toArray() or other similar method of conversion:

       var ObjectID = require('mongodb').ObjectID;

       db.collection("Product").find({
           'entry_id': new ObjectID(entryID)
       }).toArray(function(err, result) {
        console.log("Output:",result);
       });
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317