Mongo DB Delete Field and Value

In mongo shell, as if to delete all occurrences of "id" : "1" , the value of the field is always different. Do I use the $ unset operator? Will this remove the value and the field?

+6
source share
1 answer

You say delete all occurrences in the field, right? If yes, then it should be like this:

 db.collection.update( { id: { $exists: true } }, // criteria { $unset: { id: 1 } }, // modifier false, // no need to upsert true // multi-update ); 
+16
source

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


All Articles