Interface StrictUpdateFilter<Schema>

Represents the update filter to specify how to update a document.

If you want relaxed type-checking, see UpdateFilter.

This is a stricter version of UpdateFilter that type-checks nested fields.

You can use it anywhere by using the satisfies keyword, or by creating a temporary const with the StrictUpdateFilter type.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $set: {
  'customer.name': 'Jim B.'
  },
  $unset: {
  'customer.phone': ''
  },
  $inc: {
  'customer.age': 1
  },
} satisfies StrictUpdateFilter<SomeDoc>

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.

See

UpdateFilter

interface StrictUpdateFilter<Schema> {
    $addToSet?: StrictPush<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $currentDate?: CurrentDate<Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $inc?: StrictNumberUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $max?: StrictNumberUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>> | StrictDateUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $min?: StrictNumberUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>> | StrictDateUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $mul?: StrictNumberUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $pop?: StrictPop<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $push?: StrictPush<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $rename?: StrictRename<Schema>;
    $set?: Partial<Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $setOnInsert?: Partial<Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>;
    $unset?: StrictUnset<Schema>;
}

Type Parameters

Properties

$addToSet?: StrictPush<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Add an element to an array field in the document if it does not already exist.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $addToSet: {
  'items': 'Extended warranty - 5 years'
  }
}
$currentDate?: CurrentDate<Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Set the value of a field to the current date.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $currentDate: {
  'purchase_date': true
  }
}
$inc?: StrictNumberUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Increment the value of a field in the document if it's potentially a number.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $inc: {
  'customer.age': 1
  }
}
$max?: StrictNumberUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>> | StrictDateUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Only update the field if the specified value is greater than the existing value.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $max: {
  'customer.age': 65
  }
}
$min?: StrictNumberUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>> | StrictDateUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Only update the field if the specified value is less than the existing value.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $min: {
  'customer.age': 18
  }
}
$mul?: StrictNumberUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Multiply the value of a field in the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $mul: {
  'customer.age': 1.1
  }
}
$pop?: StrictPop<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Remove an element from an array field in the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $pop: {
  'items': -1
  }
}
$push?: StrictPush<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Add an element to an array field in the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $push: {
  'items': 'Extended warranty - 5 years'
  }
}
$rename?: StrictRename<Schema>

Rename a field in the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $rename: {
  'customer.name': 'client.name'
  }
}
$set?: Partial<Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Set the value of a field in the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $set: {
  'customer.name': 'Jim B.'
  }
}
$setOnInsert?: Partial<Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>>

Set the value of a field in the document if an upsert is performed.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $setOnInsert: {
  'customer.name': 'Jim B.'
  }
}

Remove the field from the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $unset: {
  'customer.phone': ''
  }
}