1,747
社区成员
发帖
与我相关
我的任务
分享
[
{ id: 1, category: 'computer', value: 1 },
{ id: 2, category: 'computer', value: 2 },
{ id: 3, category: 'book', value: 2 },
]
const query = [
{ category: 'computer', value: 1 },
{ category: 'book', value: 2 }
]
[
{ id: 1, category: 'computer', value: 1 },
{ id: 3, category: 'book', value: 2 },
]
db.collection.find({ $category: { $in: query.map(one => one.category) }, value: { $in: query.map(one => one.value) } })
,但这样会多筛选出一些结果,比如 { id: 2, category: 'computer', value: 2 }
这条记录也会被筛选出来,而这并不是期望结果。