The method can modify specific fields of an existing document or documents or replace an existing document entirely, depending on the. By default, the method updates a single document. Set the to update all documents that match the query criteria. The method has the following form: db. The same as in the method are available. For more information and an example, see. If set to true, creates a new document when no document matches the query criteria. The default value is false, which does not insert a new document when no match is found. If set to true, updates multiple documents that meet the query criteria. If set to false, updates one document. The default value mongo db version false. Omit to use the default write concern. Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see. Specifies the to use for the operation. The collation option has the following syntax: collation : locale :caseLevel :caseFirst :strength :numericOrdering :alternate :maxVariable :backwards : When specifying collation, the locale field is mandatory; all other collation fields are optional. For descriptions of the fields, see. If the collation is unspecified but the collection has a default collation seethe operation uses the collation specified for the collection. You cannot specify multiple collations for an operation. For example, you cannot specify different collations per field, or if performing a find with a sort, you cannot use one collation for the find and another for the sort. An array of filter documents that determines which array elements to modify for an update operation on an array field. In the update document, use the filtered positional operator to define an identifier, which you then reference in the array filter documents. You cannot have an array filter document for an identifier if the identifier is not included in the update document. Note The must begin with a lowercase letter and contain only alphanumeric characters. That is, you cannot specify multiple array filter documents for the same identifier. To update an embedded document or an array as a whole, specify the replacement value for the field. To update particular fields in an embedded document or in an array, use to specify the field. Upsert Behavior If upsert is true and no document matches the query criteria, inserts a single document. The update creates a base document from the equality clauses in the parameter, and then applies the update expressions from the parameter. If upsert is true and there are documents that match the query criteria, performs an update. Warning To avoid inserting the same document more than once, only use upsert: true if the mongo db version field is uniquely indexed. Given a collection named people where no documents have a name field that holds the value Andy. Consider when multiple clients issue the following update with upsert: true at the same time: db. With a unique index, if multiple applications issue the same update with upsert: true, exactly one would successfully insert a new document. If the operation fails because of a duplicate index key error, applications may retry the operation which will succeed as an update operation. mongo db version For example, consider the following update operation. Mongo db version Parameter If multi is set to true, the method updates all documents that meet the criteria. If the document contains only field:value expressions, then cannot update multiple documents. Important In most cases, multi-document transaction incurs a greater performance cost over single document writes, and the availability of multi-document transaction should not be a replacement for effective schema design. For many scenarios, the will continue to be optimal for your data and use cases. That is, for many scenarios, modeling your data appropriately will minimize the need for multi-document transactions. mongo db version That is, the fields ratings and reorder no longer exist in the updated document since the fields were not in the replacement document. If matching documents exist, the operation updates all matching documents. If no matching documents exist, the operation inserts a new document.