Understanding Database Update Operators

When performing updates on objects in MongoDB, you need to specify exactly what fields need to be changed and how they need to be changed. Unlike in SQL, where you create long query strings to define an update, in MongoDB you can implement an update object with operators that define exactly how to change the data in the documents.

You can include as many operators in the update object as you need. The format of the update object is shown below:

{  <operator>: {<field_operation>, <field_operation>, . . .},  <operator>: {<field_operation>, <field_operation>, . . .}  . . .}

For example, consider the following object:

{  name: "myName",  countA: 0, ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.