Which update operator is used to **modify or add** a specific field?
Analysis & Theory
`$set` is used to update the value of a field or add it if it doesn’t exist.
Which operator is used to **increase** the value of a numeric field?
Analysis & Theory
`$inc` increases or decreases a number field’s value. Example: `{ $inc: { age: 1 } }`.
What does `$unset` do?
C
Removes a field from the document
D
Replaces the entire document
Analysis & Theory
`$unset` removes the specified field from the document.
Which operator is used to rename a field?
Analysis & Theory
`$rename` changes the name of a field. Example: `{ $rename: { 'oldName': 'newName' } }`.
Which operator adds a value to an array field?
Analysis & Theory
`$push` appends a value to an array. Example: `{ $push: { tags: 'mongodb' } }`.
What does `$addToSet` do?
A
Adds a field to a set collection
B
Adds a value to an array only if it doesn't exist
C
Replaces the array with a new set
D
Updates every field in a document
Analysis & Theory
`$addToSet` ensures that duplicates are **not** added to an array.
Which operator removes the **last element** from an array?
Analysis & Theory
`$pop: 1` removes the **last** element, `$pop: -1` removes the **first**.
How do you remove a specific value from an array?
Analysis & Theory
`$pull` removes specific values from arrays. Example: `{ $pull: { tags: 'spam' } }`.
What operator allows updating multiple array elements by condition?
Analysis & Theory
`$arrayFilter` is used in conjunction with `$set` to update multiple array items conditionally.
Which operator is used with `$push` to add multiple values at once?
Analysis & Theory
`$each` is used inside `$push` to add multiple elements to an array.