为了填充缓存,我需要查询所有已经在一段时间内售出门票的俱乐部。因此,我查询所有已售出的门票,并遍历所有门票,以找到给定时间段的活动俱乐部列表。但是,如果计算量很大,几乎每分钟都要运行大量的票,那么这就影响了我的基础设施费用。如何进行更有效的查询?
文档
{
id: "32r34r34r3r434r4r",
creationDate: 18909894344,
clubId: "9685ut56tu9t698t9",
type:"TICKET"
}集合
...
{clubId: "3e32e4r43r43r43r4",...},
{clubId: "3e32e4r43r43r43r4",...},
{clubId: "5t89u54u895tu95t8",...},
{clubId: "6t68ut986ut986ut9",...},
....我要去找
[
"3e32e4r43r43r43r4"
"5t89u54u895tu95t8"
"6t68ut986ut986ut9"
]发布于 2019-03-14 16:29:11
你能试试这个吗?
db.collection.aggregate([
{
$group:{
_id:null,
clubIds:{$addToSet:"$clubId"}
}
}
])发布于 2019-03-14 17:32:43
您可以向distinct传递一个查询以完成以下操作:
db.collection.distinct('clubId', query)https://stackoverflow.com/questions/55166583
复制相似问题