Class CollectionInsertManyError

Overview

Represents an error that occurred during an insertMany operation (which may be paginated).

Contains the inserted IDs of the documents that were successfully inserted, as well as the cumulative errors that occurred during the operation.

If the operation was ordered, the insertedIds will be in the same order as the documents that were attempted to be inserted.

Example

try {
  await collection.insertMany([
  { _id: 'id1', desc: 'An innocent little document' },
  { _id: 'id2', name: 'Another little document minding its own business' },
  { _id: 'id2', name: 'A mean document commiting _identity theft' },
  { _id: 'id3', name: 'A document that will never see the light of day-tabase' },
  ], { ordered: true });
} catch (e) {
  if (e instanceof CollectionInsertManyError) {
  console.log(e.message); // "Document already exists with the given _id"
  console.log(e.partialResult.insertedIds); // ['id1', 'id2']
  }
}
Collections vs Tables

There is a sister TableInsertManyError class that is used for insertMany operations on tables. It's identical in structure, but just uses the appropriate TableInsertManyResult type.

Field

message - A human-readable message describing the first error

Field

errorDescriptors - A list of error descriptors representing the individual errors returned by the API

Field

detailedErrorDescriptors - A list of errors 1:1 with the number of errorful API requests made to the server.

Field

partialResult - The partial result of the InsertMany operation that was performed

Hierarchy (view full)

Constructors

Properties

detailedErrorDescriptors: DataAPIDetailedErrorDescriptor[]

A list of errors 1:1 with the number of errorful API requests made to the server. Each element contains the original command, the raw response, and the error descriptors for that request.

For operations that only make one request, this will be a singleton list (i.e. insertOne).

errorDescriptors: DataAPIErrorDescriptor[]

A list of error descriptors representing the individual errors returned by the API.

This is always equal to detailedErrorDescriptors.flatMap(d => d.errorDescriptors), for the user's convenience.

message: string

A human-readable message describing the first error.

This is always equal to errorDescriptors[0]?.message if it exists, otherwise it's given a generic default message.

name: string = 'CollectionInsertManyError'

The name of the error. This is always 'InsertManyError'.

The partial result of the InsertMany operation that was performed. This is always defined, and is the result of all successful insertions.

stack?: string
prepareStackTrace?: ((err, stackTraces) => any)

Optional override for formatting stack traces

Type declaration

    • (err, stackTraces): any
    • Parameters

      • err: Error
      • stackTraces: CallSite[]

      Returns any

stackTraceLimit: number

Methods

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • Optional constructorOpt: Function

    Returns void