我有一个收集会议。我想使用angular js逐个打印所有文档。
我的代码:
collection.find().toArray(function(error,data){
if (error) {
// Hopefully we pass the error to the error handler
console.log("Error :" + error);
} else {
// If everything goes fine we send the data.
console.log("Collection Data = " + data);
//console.log("Collection count =" + self.collection);
}
});
我的输出如下:
Collection Data = [object Object],[object Object],[object Object],[object Object
],[object Object],[object Object],[object Object],[object Object],[object Object
],[object Object],[object Object],[object Object],[object Object],[object Object
],[object Object],[object Object],[object Object],[object Object],[object Object
],[object Object],[object Object],[object Object],[object Object],[object Object
],[object Object],[object Object],[object Object],[object Object],[object Object
],[object Object],[object Object],[object Object],[object Object],[object Object
],[object Object],[object Object],[object Object],[object Object],[object Object
请告诉我我失踪的地方。
答案 0 :(得分:1)
mongo将光标返回给JSON文档并将其存储在data
中。您可以使用mongo特定函数printjson
:
printjson(data[i])
或使用函数forEach
:
collection.find().forEach(printjson)