【问题标题】:Delete a specific data from mongo从 mongo 中删除特定数据
【发布时间】:2023-03-05 22:29:02
【问题描述】:

我想从 mongo 中删除特定数据。下面是我的json。我想删除所有出现的 IIT-395。

{
"_id" : "i34908s",
"lifeStageCourses" : [ 
    {
        "lifeStage" : "in_school",
        "tags" : [ 
            "IIT-182"

        ],
        "courseIds" : []
    }, 
    {
        "lifeStage" : "in_college",
        "tags" : [ 
            "IIT-134", 
            "IIT-140",
            "IIT-395"
        ],
        "courseIds" : []
    }, 
    {
        "lifeStage" : "prep_entrance_exam",
        "tags" : [],
        "courseIds" : []
    }, 
    {
        "lifeStage" : "job_seeker",
        "tags" : [ 
            "IIT-134",
            "IIT-395"
        ],
        "courseIds" : []
    }
]
}

我希望只删除输出 IIT-395

整个文档都被删除了。

【问题讨论】:

    标签: php mongodb mongodb-query


    【解决方案1】:

    尝试以下查询。

    db.getCollection('careerpaths').update(
        {"lifeStageCourses.tags" : "IIT-395"},
        {$pull : {
            "lifeStageCourses.$[].tags" :"IIT-395"
            }},false, true
        );
    

    【讨论】:

      猜你喜欢
      • 2021-04-18
      • 2019-09-20
      • 2019-01-24
      • 2015-10-15
      • 2017-08-17
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多