从数组 mongodb 中的特定对象元素投影一个字段
我有一个集合:
{
"_id": 1,
"_deleted": false,
"customFields": [{
"fieldName": "sapID",
"value": ""
}, {
"fieldName": "salesTerritory",
"value": ""
}, {
"fieldName": "clientType",
"value": "Corporate"
}],
}
如何project(aggregate)
仅使用fieldName =“clientType”
元素的value
字段:
db.collection.aggregate(
{
$project:{value:<code>}
}
)
我尝试了< code>$filter 但它不起作用
I have a collection:
{
"_id": 1,
"_deleted": false,
"customFields": [{
"fieldName": "sapID",
"value": ""
}, {
"fieldName": "salesTerritory",
"value": ""
}, {
"fieldName": "clientType",
"value": "Corporate"
}],
}
How can I project(aggregate)
only the value
field of the element with fieldName = "clientType"
:
db.collection.aggregate(
{
$project:{value:<code>}
}
)
I tried $filter
but it does not work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
mongoplayground
mongoplayground
mongoplayground
mongoplayground
这又如何呢?
Mongo 游乐场
What about this?
Mongo Playground