Update Documents: Part 1
Learn and practice commands to perform updates on single and multiple documents.
We'll cover the following...
Update single document
We use the below commands to update a single document.
db.<collection-name>.updateOne(
<filter query>,
<update document>,
<options>
);
Filter query
filter query
is used to build criteria to fetch documents. This should return only one document if used with the updateOne
method.
Update document
The updated document contains modifications that need to apply to the document. Through this document, we can:
- Replace a field value
- Add a new field
- Increment or decrement a number
- Add a new value in the array
- Remove a value from the array
- Perform modification on