【发布时间】:2020-01-08 13:39:55
【问题描述】:
哪个 MongoDB 查询会返回 Team 记录,其中一个城市在集合中至少出现两次并且它们处于活动状态?
如果你只能回答第一部分也有帮助。 (返回该城市至少出现两次的记录)
团队
[
{teamName: 'Red', city: 'Altanta', active: false},
{teamName: 'Blue', city: 'NYC', active: true},
{teamName:'Yellow', city: 'NYC', active: false},
{teamName:'Green', city: 'NYC', active: true},
{teamName:'Gray', city: 'Atlanta', active: false},
{teamName:'Purple', city: 'Atlanta', active: true},
{teamName:'Black', city: 'Boston', active: false},
{teamName:'Brown', city: 'Boston', active: true},
{teamName:'Silver', city: 'Miami', active: false},
{teamName:'White', city: 'Austin', active: true},
{teamName:'Gold', city: 'Detroit', active: true},
]
查询将返回:
[
{teamName: 'Blue', city: 'NYC', active: true},
{teamName:'Green', city: 'NYC', active: true},
{teamName:'Purple', city: 'Atlanta', active: true},
{teamName:'Brown', city: 'Boston', active: true},
]
【问题讨论】:
-
您是否必须首先检查
active:true或首先获取城市重复的文件然后检查活动?因为如果我们首先检查活动,那么您将看不到Atlanta和Boston
标签: mongodb mongoose mongodb-query