diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 769ee5c1b5..f0699fb24b 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -30,6 +30,7 @@ // Piotr Błażejewicz // Linus Unnebäck // Richard Bateman +// Igor Strebezhev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 @@ -1851,24 +1852,78 @@ export interface BulkWriteResultUpsertedIdObject { _id: ObjectId; } -/** http://mongodb.github.io/node-mongodb-native/3.1/api/BulkWriteResult.html */ +/** http://mongodb.github.io/node-mongodb-native/3.5/api/BulkWriteResult.html */ export interface BulkWriteResult { - ok: number; + /** + * Evaluates to `true` if the bulk operation correctly executes + */ + ok: boolean; + + /** + * The number of documents inserted, excluding upserted documents. + * + * @see {@link nUpserted} for the number of documents inserted through an upsert. + */ nInserted: number; - nUpdated: number; - nUpserted: number; + + /** + * The number of documents selected for update. + * + * If the update operation results in no change to the document, + * e.g. `$set` expression updates the value to the current value, + * {@link nMatched} can be greater than {@link nModified}. + */ + nMatched: number; + + /** + * The number of existing documents updated. + * + * If the update/replacement operation results in no change to the document, + * such as setting the value of the field to its current value, + * {@link nModified} can be less than {@link nMatched} + */ nModified: number; + + /** + * The number of documents inserted by an + * [upsert]{@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#upsert-parameter}. + */ + nUpserted: number; + + /** + * The number of documents removed. + */ nRemoved: number; + // Returns an array of all inserted ids getInsertedIds(): object[]; + // Retrieve lastOp if available getLastOp(): object; + // Returns raw internal result getRawResponse(): object; + + /** + * Returns the upserted id at the given index + * @param index the number of the upserted id to return, returns `undefined` if no result for passed in index + */ getUpsertedIdAt(index: number): BulkWriteResultUpsertedIdObject; + + // Returns an array of all upserted ids getUpsertedIds(): BulkWriteResultUpsertedIdObject[]; + // Retrieve the write concern error if any getWriteConcernError(): WriteConcernError; + + /** + * Returns a specific write error object + * @param index of the write error to return, returns `null` if there is no result for passed in index + */ getWriteErrorAt(index: number): WriteError; + + // Returns the number of write errors off the bulk operation getWriteErrorCount(): number; + // Retrieve all write errors getWriteErrors(): object[]; + // Returns `true` if the bulk operation contains a write error hasWriteErrors(): boolean; }