upsert property

bool upsert
getter/setter pair

Used in conjunction with the update field.

When true, findAndModify() either:

  • Creates a new document if no documents match the query. For more details see upsert behavior.
  • Updates a single document that matches the query.

To avoid multiple upserts, ensure that the query fields are uniquely indexed.

Defaults to false.

Implementation

bool upsert;