MongoDB uses $ pull to remove dictionary in array subdot

I am trying to remove the following dict in this array:

{
"ProjectID": "8ToGTAUjT+CbcH68ZYuW8Q=="
"Tasks": [
    {
        "description": "",
        "title": "testcounter",
        "notes": "",
        "percentComplete": "100",
        "completedDate": {
            "hour": "12",
            "year": "2014",
            "day": "14",
            "minute": "43",
            "month": "11"
        },
        "completed": "",
        "ProjectID": "8ToGTAUjT+CbcH68ZYuW8Q==",
        "TaskID": "JxHddpQNSguzOqg1sdsdKtyQ=="
    },
    ......
 ],
 ......
 }

      

Tasks

is a subdocument in this entry.

I am trying to remove using this:

 db.projects.update({'ProjectID': "8ToGTAUjT+CbcH68ZYuW8Q=="}, 
                      {'$pull': {'Tasks.TaskID': "JxHddpQNSguzOqg1sdsdKtyQ=="}})

      

This, however, does not remove this subdocument. How can I remove this character in an array?

+3


source to share


1 answer


Try using this code:

db.projects.update(
  {'ProjectID': "8ToGTAUjT+CbcH68ZYuW8Q=="}, 
  {'$pull': {Tasks:{ TaskID: "JxHddpQNSguzOqg1sdsdKtyQ=="}}}
)

      



The expression $pull

applies a condition to each item in the task array as if it were a top-level document.

+8


source







All Articles