【发布时间】:2020-08-31 16:51:21
【问题描述】:
我的 MongoDB 集合中的文档如下所示:
我的 Mongo 版本是 4.2.3
{
"_id": "SAGE-UW-00005",
"carriers": [
{
"bindable": true,
"carrierCode": "LMICO",
"mapped": true,
"products": [
{
"industries": [
{
"industryCode": null,
"states": "GA"
}
],
"isAllNCCIValid": null,
"isAllstateValid": true,
}
],
"questionCode": "LMGENRL17"
}
],
"column": 1,
"dataType": null,
}
这是我想要的输出:
{
"_id": "SAGE-UW-00005",
"carriers": [
{
"bindable": true,
"carrierCode": "LMICO",
"mapped": true,
"products": [
{
"industries": [
{
"states": "GA"
}
],
"isAllstateValid": true,
}
],
"questionCode": "LMGENRL17"
}
],
"column": 1,
}
我不确定集合中嵌套子文档的深度,但集合中应该有很多空字段。我的后端代码使用 $exists 来查询集合中的字段,所以 null 在这里造成了问题。
【问题讨论】:
-
@Gibbs,是的。链接中的解决方案似乎对我不起作用,
-
一般来说,您需要知道您尝试更新(或删除)的字段。这将使您的任务更轻松。您可以利用 Aggregation Updates 和 Array Update Operators 等功能。
-
@prasad_gotcha。会调查的。
标签: arrays mongodb nosql mongo-shell