因此,我在我的应用程序中创建了一个搜索栏,并使用mongodb来获取结果。情况如下:
当post文档的_group属性(它是一个ObjectId)等于exampleArray中的一个值时,我希望这篇文章包含在我的最终结果中。我该怎么做呢?
const exampleArray = ['ObjectId1', 'ObjectId1', 'ObjectId1'];
const posts = await Post.find({_group: exampleArray })
发布于 2019-02-22 21:48:52
查询将需要使用MongoDB $in operator,它用于将字段与值列表进行比较。
尝试以下操作:
posts = await Post.find({_group: { "$in" : exampleArray } })
https://stackoverflow.com/questions/54834159
复制相似问题