我正在尝试使用 MongoDB,并向“users”集合中输入了一些测试数据 {name:"david"}。通过在 mongo shell 中输入,我验证了数据已经存入 MongoDB:
db.users.find()
结果:
{ "name":"david" }
在node.js脚本中,以下代码:
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();
});
没有返回任何结果
我没有看到任何问题,也没有错误返回。请给予建议。