Data Updation in MongoDB
While updating data in document, we will come across various scenarios, let us analyze them step by step.
- Now, we will update field name with some other value like ABC, below find the code snippet for the same.The updated output is:The value of field name is updated from xyz to ABC.
- Considering a scenario, where we have an array for field friendsand if we want to update that array by adding values, we can do it by referring the below code snippet:and Amit is added to the array against field friends.
- We can even add object to the array of object using update query. For an example, for against field comments, if we want to add multiple objects with various field, it is possible.Here is the code snippet:and the corresponding output is:
No comments:
Post a Comment