0

How do you unset a value like treatment, likes or disease? I tried

db.myCollection.update({first_name:"QQQ"},{$unset:{"history.treatment":1}});

It finds the match, but it doesn't unset it. What am I doing wrong?

myCollection:

 { first_name: "QQQ",
last_name: "BBBB",

"history" : [
                {
                        "disease" : [
                                "X",
                                "Y",
                                "Z"
                        ],
                        "treatment" : "No treatment",
                        "likes" : "french fries"
                }
        ]}
Joe
  • 1,076
  • 3
  • 10
  • 17

1 Answers1

1

Treatement is nested inside history array so you need to use $[] positional operator

db.myCollection.update({first_name:"QQQ"},{$unset:{"history.$[].treatment":1}});
Shivam
  • 3,514
  • 2
  • 13
  • 27
  • Thank you! Yes! I saw the array, but I really had no idea how to access it! Thanks again! – Joe Nov 27 '19 at 06:35