Interface UpdateFilter<Schema>

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

If you want stricter type-checking and full auto-complete, see StrictUpdateFilter.

This is a more relaxed version of StrictUpdateFilter that doesn't type-check nested fields.

Example

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

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

StrictUpdateFilter

interface UpdateFilter<Schema> {
    $addToSet?: Push<Schema> & SomeDoc;
    $currentDate?: CurrentDate<Schema> & Record<string, boolean>;
    $inc?: NumberUpdate<Schema> & Record<string, number>;
    $max?: (NumberUpdate<Schema> | DateUpdate<Schema>) & Record<string, number | bigint | Date | { $date: number; }>;
    $min?: (NumberUpdate<Schema> | DateUpdate<Schema>) & Record<string, number | bigint | Date | { $date: number; }>;
    $mul?: StrictNumberUpdate<Schema, Expand<UnionToIntersection<_ToDotNotation<Schema, "", Required<Schema>>>>> & Record<string, number>;
    $pop?: Pop<Schema> & Record<string, number>;
    $push?: Push<Schema> & SomeDoc;
    $rename?: Record<string, string>;
    $set?: Partial<Schema> & SomeDoc;
    $setOnInsert?: Partial<Schema> & SomeDoc;
    $unset?: Record<string, true | "" | 1>;
}

Type Parameters

Properties

$addToSet?: Push<Schema> & SomeDoc

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<Schema> & Record<string, boolean>

Set the value of a field to the current date.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $currentDate: {
  'purchase_date': true
  }
}
$inc?: NumberUpdate<Schema> & Record<string, number>

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?: (NumberUpdate<Schema> | DateUpdate<Schema>) & Record<string, number | bigint | Date | { $date: number; }>

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

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $max: {
  'customer.age': 65
  }
}
$min?: (NumberUpdate<Schema> | DateUpdate<Schema>) & Record<string, number | bigint | Date | { $date: number; }>

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>>>>> & Record<string, number>

Multiply the value of a field in the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $mul: {
  'customer.age': 1.1
  }
}
$pop?: Pop<Schema> & Record<string, number>

Remove an element from an array field in the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $pop: {
  'items': -1
  }
}
$push?: Push<Schema> & SomeDoc

Add an element to an array field in the document.

Example

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

Rename a field in the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $rename: {
  'customer.name': 'client.name'
  }
}
$set?: Partial<Schema> & SomeDoc

Set the value of a field in the document.

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $set: {
  'customer.name': 'Jim B.'
  }
}
$setOnInsert?: Partial<Schema> & SomeDoc

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

Example

const updateFilter: UpdateFilter<SomeDoc> = {
  $setOnInsert: {
  'customer.name': 'Jim B.'
  }
}
$unset?: Record<string, true | "" | 1>

Remove the field from the document.

Example

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