MongoDb callback returns value undefined whereas Mongo shell returns the right results

170 views Asked by At

I've a mongodb collection which has more than 20 million collection.

db.collection.find({ 'attr.type': new RegExp('automotive snow' 'i') }).limit(10);

Above mongo shell query returns the results as expected, But implementing the same in a node.js application it doesn't seem to work right. I can't really figure out the reason.

Sample node.js code

db.collection.find({ 'attr.type': new RegExp('automotive snow' 'i') }, function(err, docs) {
 console.log(docs); // returns undefined
});

I use mongojs module, Tried native mongodb module as well but the results seemed to be the same hence decided to use mongojs module.

Does anyone know what the issue is?

0

There are 0 answers