我正在尝试从数组中获取数据,并希望将其传递给$ in运算符内的查询查询 . 但它给出了一个错误的说法
$ in需要一个数组
const fileIds = _.get(result, 'files', []);
console.log(fileIds);
db.collection('files').find({_id: {$in: fileIds}}).toArray((err, files) =>
{
// some statements....
}
这是console.log(fileIds)的输出
{'0':5a8f24ab281bd22cd940530b,'1':5a8f24ab281bd22cd940530c}
在标记复制之前我已经看过这篇文章 .
How to return the ObjectId or _id of an document in MongoDB? and error "$in needs an array"
但这些都没有帮助 . 所以,如果有人知道答案,请帮助 . 提前致谢 .
1 回答