为什么 db.find
不起作用? console.log
未定义...
var course = (db.courses.find({ _id: mongo.helper.toObjectID(param.course)}));
console.log(course.body)
最佳答案
您尝试使用的方式选择集合中的文档并将光标返回到所选文档。
,因此您无法使用您尝试使用它的方式。
您需要使用 callback()
来获取与查询匹配的记录。
下面的代码将以数组格式给出结果:-
db.courses.findOne({ _id: mongo.helper.toObjectID(param.course)}).toArray(function(err, result)
{
console.log(result[0]); // will give you the matched record.
})
关于Mongodb 查找()不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37570094/