【发布时间】:2013-09-23 01:17:11
【问题描述】:
我有两个 MongoDB 集合。 questions:
{
"_id" : "8735574",
"title" : "...",
"owner" : {
"user_id" : 950690
},
}
{
"_id" : "8736808",
"title" : "...",
"owner" : {
"user_id" : 657258
},
}
和users:
{
"_id" : 950690,
"updated" : SomeDate,
...
}
{
"_id" : 657258,
"updated" : SomeDate,
...
}
users 中的条目必须基于questions 定期创建或更新。因此,我想从questions 中获取所有user_ids,它们要么根本没有users 中的条目,要么它们在users 中的条目比updated 更多。一天前。
为了实现这一点,我可以从questions 中读取所有user_ids,然后从结果中手动删除不需要更新的所有用户。但这似乎是一个糟糕的解决方案,因为它读取了大量不必要的数据。有没有办法以不同的方式解决这个问题?某种集合连接会很棒,但我知道这在 MongoDB 中(真的)不存在。有什么建议吗?
PS:将这些集合嵌套到一个集合中不是解决方案,因为users 也必须从其他地方引用。
【问题讨论】:
标签: mongodb