首页 > 解决方案 > 遍历 mongoose 文档列表返回 0

问题描述

我有一个猫鼬模式,它由作者对象、内容、评论、cotes、creationDate、creationIP 和 creationLocation 组成。问题是,如果我遍历 Application.find() 返回的列表,它似乎找不到任何文档。

我的代码

这是在 async () => {} 函数中。

const applications = await Application.find(
    { _id: user.notReviewed },
    { _id: true, content: true, creationDate: true, author: true, votes: true });

console.log(applications)

for (application in applications) {
    console.log(application)
}

返回

[ { author: { username: 'Dextication', _id: '1234567890' },
    votes: [],
    creationDate: 2019-04-26T15:24:37.000Z,
    _id: 5cc321e529b4745b3474a641,
    content: 'Yeah, well that was fun!' } ]
0 // this should be the above argument in the array

标签: arraysnode.jsmongodbmongoose

解决方案


推荐阅读