Sign In Register

How can we help you today?

Start a new topic
Answered

Remove array element

Hello everybody, i want to delete an array element in a runtime collection, im using delete(arrayelement[i]) but this is not working for me as it sets the value to "null" and this is not what i need, i need the array element to dissapear from the array, any help would be appreciated, thanks.


Best Answer

Try to take a look here: https://docs.mongodb.com/manual/reference/operator/update/pull/

Also some example how to use it: 

myCollection.update({"_id":"MyDocument"}, {$pull: {"myField": "whatToPull"}});

 you can combine it with conditions, more fields of your choice.



Answer

Try to take a look here: https://docs.mongodb.com/manual/reference/operator/update/pull/

Also some example how to use it: 

myCollection.update({"_id":"MyDocument"}, {$pull: {"myField": "whatToPull"}});

 you can combine it with conditions, more fields of your choice.



1 person likes this

Works perfect, lot of thanks Daniel

Login to post a comment