Remove a field from all elements in array in mongodb

Codes here !

Moderators: egami, macek, gesf

Post Reply
User avatar
hannabone3445
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Sep 21, 2021 2:26 pm
Contact:

Tue Sep 21, 2021 2:42 pm

I have document in MongoDB(2.4.5)

I want to remove withBase filed from array elements inside casts.crew ..

I tried this

Code: Select all

db.coll.update({_id:235399},{$unset: {  "casts.crew.withBase" : 1 } },false,true)
nothing changed.

And tried this..

Code: Select all

db.coll.update({_id:235399},{$unset: {  "casts.crew" : { $elemMatch: { "withBase": 1 } } } },false,true)
it removed entire crew array from the document.

Can someone please provide me the right query?
Post Reply