【发布时间】:2021-07-28 22:10:48
【问题描述】:
我有以下 mongo db 模式,我正在尝试构建一个聚合查询,该查询在 repo 键下的 github_open_issues 下搜索,并且可以返回一个匹配所有以 repoA 为值的值。我尝试了以下作为我的查询,但它没有返回任何结果。我有点困惑为什么这不起作用,因为我有另一个具有类似于此模式的数据库,并且这种类型的查询在那里工作,但这里的东西似乎有所不同并且不起作用。我还整理了这个互动示例mongoplayground
查询
db.collection.aggregate([
{
"$unwind": "$github_open_issues"
},
{
"$match": {
"github_open_issues.repo": {
"$in": [
"repoA"
]
}
}
},
])
架构
[
{
"github_open_issues": {
"0": {
"git_url": "https://github.com/",
"git_assignees": "None",
"git_open_date": "2019-09-26",
"git_id": 253113,
"repo": "repoA",
"git_user": "userA",
"state": "open"
},
"1": {
"git_url": "https://github.com/",
"git_assignees": "None",
"git_open_date": "2019-11-15",
"git_id": 294398,
"repo": "repoB",
"git_user": "userB",
"state": "open"
},
"2": {
"git_url": "https://github.com/",
"git_assignees": "None",
"git_open_date": "2021-04-12",
"git_id": 661208,
"repo": "repoA",
"state": "open"
}
},
"unique_label_seen": {
"568": {
"label_name": "some label",
"times_seen": 12,
"535": {
"label_name": "another label",
"times_seen": 1
}
}
}
}
]
【问题讨论】:
-
github_open_issues字段是对象,它实际上是数据库中的对象吗? -
首先感谢您的问题,但我不完全理解它,但是 github_open_issues 是对象,它实际上在数据库中。我有完整的工作示例,我在这里复制了我的问题mongoplayground.net/p/IdPWMU1yPdX
标签: mongodb mongodb-query aggregation-framework pymongo