我有两个系列
- 用于保存以下用户的集合
- 用户故事集
我只想看到我关注的用户的故事
这是我的数据库示例
db = {
"follow": [
{
"_id": 1,
"start": "user1",
"end": "user2",
},
{
"_id": 2,
"start": "user2",
"end": "user3",
}
],
"story": [
{
"_id": 1,
"owner_id": "user2",
"updated_at": 1638090000,
"deleted_at": null
},
{
"_id": 2,
"owner_id": "user3",
"updated_at": 1638080000,
"deleted_at": null
}
]
}
我想要这样一个问题.当然,这是错误的:
db.story.aggregate([
{
"$match": {
"deleted_at": null,
"updated_at": {
$gte: 1638081000
},
"owner_id": {
$in: [
db.follow.find({"start": "user1"})
]
}
}
}
])
Note that I want all of this to be done in one query
mongoplayground 查询:https://mongoplayground.net/p/ysRUDW4hRzh