【发布时间】:2017-07-20 23:00:39
【问题描述】:
我正在尝试计算集合中所有文档的数量(我知道我可以使用collection.count(),但我想获取所有文档以进行进一步操作)。这是我的尝试:
collection.find({},function(err, doc)
{
if(err)
{
console.log(err)
}
console.log(doc); //using this I can see the cursor
doc.toArray(function(errx, docx)
{
if(errx)
{
console.log(errx);
}
console.log(docx.length);
});
});
代码显示光标的内容,但不显示有关数组的任何内容。你能告诉我哪一步是错的吗?提前致谢。
【问题讨论】:
标签: javascript node.js mongodb