I was playing around with mongodb and entered some test data {name:"david"} into the 'users' collection. I verified that the data was in MongoDB using the mongo shell by typing
db.users.find()
result:
{ "name":"david" }
In node.js script, the following code:
db.open(function(err, db) {
if (!err) {
console.log("db opened!");
}
else {
console.log(err);
}
db.collection('users', function(err, collection) {
collection.find({}, function(err, cursor) {
cursor.each(function(err, item) {
console.log(item);
});
});
});
db.close();
});
does not return any results
I don't see anything wrong, and no err returns. Please advise