Remove a field from all elements in array in mongodb [duplicate]

You can use the new positional identifier to update multiple elements in array in 3.6.

Something like

 db.coll.update( {_id:235399}, {$unset: {"casts.crew.$[].withBase":""}} )

$[] removes all the withBase property from the crews array. It acts as a placeholder for updating all elements in array.

Use multi true to affect multiple documents.

Leave a Comment