WriteResult()

Definition

  • WriteResult()
  • A wrapper that contains the result status of the mongoshell write methods.

See

db.collection.insert(),db.collection.update(),db.collection.remove(), and db.collection.save().

Properties

The WriteResult has the following properties:

  • WriteResult.nInserted
  • The number of documents inserted, excluding upserted documents.See WriteResult.nUpserted for the number of documentsinserted through an upsert.
  • WriteResult.nMatched
  • The number of documents selected for update. If the update operationresults in no change to the document, e.g. $set expressionupdates the value to the current value,nMatched can be greater thannModified.
  • WriteResult.nModified
  • The number of existing documents updated. If the update/replacementoperation results in no change to the document, such as setting thevalue of the field to its current value,nModified can be less thannMatched.
  • WriteResult.nUpserted
  • The number of documents inserted by an upsert.
  • WriteResult._id
  • The _id of the document inserted by an upsert. Returned onlyif an upsert results in an insert.
  • WriteResult.nRemoved
  • The number of documents removed.
  • WriteResult.writeError
  • A document that contains information regarding any error, excludingwrite concern errors, encountered during the write operation.

    • WriteResult.writeError.code
    • An integer value identifying the error.

    • WriteResult.writeError.errmsg

    • A description of the error.
  • WriteResult.writeConcernError
  • A document that contains information regarding any write concern errors encounteredduring the write operation.

    • WriteResult.writeConcernError.code
    • An integer value identifying the write concern error.

    • WriteResult.writeConcernError.errInfo

    • A document identifying the write concern setting related to theerror.

    • WriteResult.writeConcernError.errmsg

    • A description of the error.

See also

WriteResult.hasWriteError(),WriteResult.hasWriteConcernError()