Lesson
Update Mongo Documents arrays using $push, $pull and $each operations
Update MongoDB arrays with $push and $pull: add single/multiple elements using $each and remove elements using in with $pull.
- Access
- Included
- Transcript
- Needs source
In this lesson, we learn that updating arrays within MongoDB documents involves using the $push and $pull operators.
The $push operator allows us to add new items to an array, while combining it with the $each operator enables us to add multiple items simultaneously.
We demonstrate how to add "Java" and ".Net" to the skills array.
Conversely, the $pull operator removes elements from an array, and we can use the in operator with $pull to remove multiple items, such as "Python" and "SQL," based on specified criteria, providing flexibility in array manipulation.