MongoDB - Discard an attribute from a single element of an array

How can I disconnect an attribute from a single element of an array from the Mongo console. For example, how do I disable the spam attribute from time to time [1]

{ "_id" : ObjectId("4d525ab2924f0000000022ad"), "name" : "hello", "time" : [ { "stamp" : "2010-07-01T12:01:03.75+02:00", "reason" : "new" }, { "stamp" : "2010-07-02T16:03:48.187+03:00", "reason" : "update", "junk" : "yes" }, { "stamp" : "2010-07-02T16:03:48.187+04:00", "reason" : "update" }, ] } 
+6
source share
1 answer

This should do the trick:

 db.coll.update({"time.junk": "yes"}, {$unset: {"time.$.junk": 1}}); 

Read the dot notation .

+11
source

Source: https://habr.com/ru/post/906092/


All Articles