【发布时间】:2021-12-16 19:51:45
【问题描述】:
如何使用投影从集合的所有文档中仅查看以下部分?
条件: 我只需要获取 "type": "DEBIT" 和以下 2 行,而不是同一类型的所有其他键。 我不想查看其他类型,例如帐户、存款。
{
"key": "Call",
"enabled": true,
}
以下结构中的示例文档。
{
"_id": "1",
"menu": [
{
"type": "ACCOUNT",
"scope": "ACCOUNT",
"items": [
{
"key": "Call",
"enabled": true,
},
{
"key": "Work",
"enabled": true,
}
]
},
{
"type": "DEPOSIT",
"scope": "DEPOSIT",
"items": [
{
"key": "Call",
"enabled": true,
},
{
"key": "Work",
"enabled": true,
}
]
},
{
"type": "DEBIT",
"scope": "DEBIT",
"items": [
{
"key": "Call",
"enabled": true,
},
{
"key": "Work",
"enabled": true,
}
]
},
]
}
【问题讨论】:
标签: arrays mongodb mongoose mongodb-query pymongo