Mongodb发现()不工作

时间:2016-06-01 13:26:26

标签: mongodb mean-stack mean database

为什么选择db.find工作? console.log未定义......

 var course = (db.courses.find({ _id: mongo.helper.toObjectID(param.course)}));
 console.log(course.body)

1 个答案:

答案 0 :(得分:2)

您尝试使用Selects documents in a collection and returns a cursor to the selected documents.的方式,因此无法使用您尝试使用它的方式。

您需要使用callback()来获取与查询匹配的记录。

以下代码将以数组格式给出结果: -

db.courses.findOne({ _id: mongo.helper.toObjectID(param.course)}).toArray(function(err, result)
{
    console.log(result[0]); // will give you the matched record.
})