我想查询mongodb以获得具有所需模式的(按优先级排序)结果,该模式使我得到类型的前两个结果:1和下两个结果类型2和类型3,然后重复
我在数据库中的数据就像
[
{"name": "A","priority": 1, "type":1},
{"name": "B","priority": 1, "type":1},
{"name": "C","priority": 1, "type":1},
{"name": "D","priority": 1, "type":1},
{"name": "E","priority": 1, "type":2},
{"name": "AA","priority": 1, "type":2},
{"name": "AB","priority": 1, "type":3},
{"name": "AAA","priority": 2, "type":1},
{"name": "BBB","priority": 2, "type":3},
{"name": "CDD","priority": 2, "type":3},
{"name": "DE","priority": 1, "type":3},
{"name": "DEE","priority": 2, "type":3},
{"name": "EFF","priority": 2, "type":1},
{"name": "ADA","priority": 2, "type":1},
{"name": "ABE","priority": 1, "type":2},
{"name": "ASA","priority": 1, "type":1}
]
我想查询mongodb以获得类似
的结果[
{"name": "A","priority": 1, "type":1},
{"name": "B","priority": 1, "type":1},
{"name": "E","priority": 1, "type":2},
{"name": "AB","priority": 1, "type":3},
{"name": "C","priority": 1, "type":1},
{"name": "DE","priority": 1, "type":1},
{"name": "AA","priority": 1, "type":2},
{"name": "DE","priority": 1, "type":3},
{"name": "D","priority": 1, "type":1},
{"name": "ABE","priority": 1, "type":2},
{"name": "AAA","priority": 2, "type":1},
{"name": "EFF","priority": 2, "type":1},
{"name": "BBB","priority": 2, "type":3},
{"name": "ADA","priority": 2, "type":1},
{"name": "CDD","priority": 2, "type":3},
{"name": "DEE","priority": 2, "type":3}
]
所以我将最终结果按优先级排序,这样列表的排列是类型1计数2,类型2计数1和类型3计数1,然后重复,如果不存在任何类型项,则移至下一个模式。