【发布时间】:2016-01-12 04:36:27
【问题描述】:
假设我在 mongo 中有以下文件:
{_id: 0, tags: ['first', 'second', 'third', fourth']},
{_id: 1, tags: ['fifth', 'seventh', 'first', second']},
{_id: 2, tags: ['eigth', 'awesometh', 'fancyth']},
{_id: 3, tags: ['fourth', 'fifteenth', 'something']},
我想从以下数组中查找包含两个或多个的文档:['first', 'second', third', 'fourth', 'fifteenth']
到目前为止,我唯一的想法是为每个组合生成一个带有子句的巨型查询,如下所示:
{$or: [
{tags: {$in: ['first', 'second']}},
{tags: {$in: ['second', 'third']}},
{tags: {$in: ['first', 'third']}},
...etc...
]
}
这显然不是一个优雅的解决方案。有没有更好的办法?
【问题讨论】:
标签: node.js mongodb mongodb-query