【发布时间】:2018-02-23 15:58:49
【问题描述】:
我正在尝试从数组中获取数据,并希望将其传递给我在 $in 运算符中的 find 查询。 但它给出了一个错误说
$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"
但这些都没有帮助。所以如果有人知道答案,请帮忙。 提前致谢。
【问题讨论】:
-
那么
fileIds是对象,而不是数组?