Optional
$addAdd an element to an array field in the document if it does not already exist.
const updateFilter: UpdateFilter<SomeDoc> = {
$addToSet: {
'items': 'Extended warranty - 5 years'
}
}
Optional
$currentSet the value of a field to the current date.
const updateFilter: UpdateFilter<SomeDoc> = {
$currentDate: {
'purchase_date': true
}
}
Optional
$incIncrement the value of a field in the document if it's potentially a number
.
const updateFilter: UpdateFilter<SomeDoc> = {
$inc: {
'customer.age': 1
}
}
Optional
$maxOnly update the field if the specified value is greater than the existing value.
const updateFilter: UpdateFilter<SomeDoc> = {
$max: {
'customer.age': 65
}
}
Optional
$minOnly update the field if the specified value is less than the existing value.
const updateFilter: UpdateFilter<SomeDoc> = {
$min: {
'customer.age': 18
}
}
Optional
$mulMultiply the value of a field in the document.
const updateFilter: UpdateFilter<SomeDoc> = {
$mul: {
'customer.age': 1.1
}
}
Optional
$popRemove an element from an array field in the document.
const updateFilter: UpdateFilter<SomeDoc> = {
$pop: {
'items': -1
}
}
Optional
$pushAdd an element to an array field in the document.
const updateFilter: UpdateFilter<SomeDoc> = {
$push: {
'items': 'Extended warranty - 5 years'
}
}
Optional
$renameRename a field in the document.
const updateFilter: UpdateFilter<SomeDoc> = {
$rename: {
'customer.name': 'client.name'
}
}
Optional
$setSet the value of a field in the document.
const updateFilter: UpdateFilter<SomeDoc> = {
$set: {
'customer.name': 'Jim B.'
}
}
Optional
$setSet the value of a field in the document if an upsert is performed.
const updateFilter: UpdateFilter<SomeDoc> = {
$setOnInsert: {
'customer.name': 'Jim B.'
}
}
Optional
$unsetRemove the field from the document.
const updateFilter: UpdateFilter<SomeDoc> = {
$unset: {
'customer.phone': ''
}
}
Represents the update filter to specify how to update a document.
If you want stricter type-checking and full auto-complete, see StrictCollectionUpdateFilter.
This is a more relaxed version of StrictCollectionUpdateFilter that doesn't type-check nested fields.
Example
Field
$set - Set the value of a field in the document.
Field
$setOnInsert - Set the value of a field in the document if an upsert is performed.
Field
$unset - Remove the field from the document.
Field
$inc - Increment the value of a field in the document.
Field
$push - Add an element to an array field in the document.
Field
$pop - Remove an element from an array field in the document.
Field
$rename - Rename a field in the document.
Field
$currentDate - Set the value of a field to the current date.
Field
$min - Only update the field if the specified value is less than the existing value.
Field
$max - Only update the field if the specified value is greater than the existing value.
Field
$mul - Multiply the value of a field in the document.
Field
$addToSet - Add an element to an array field in the document if it does not already exist.