The number of documents that were inserted into the collection.
This is always equal to the length of the insertedIds
array.
The ID of the inserted documents. These may have been autogenerated if no _id
was present in any of the inserted documents.
See CollectionInsertManyResult for more information about the inserted id.
Overview
Represents the result of an
insertMany
command on a Collection.Example
The
_id
fieldsThe type of the
_id
fields are inferred from the Collection's type, if it is present.If the collection is "untyped", or no
_id
field is present in its type, then it will default to SomeId, which is a union type covering all possible types for a document ID.You may mitigate this concern on untyped collections by using a type such as
{ _id: string } & SomeDoc
which would allow the collection to remain generally untyped while still statically enforcing the_id
type.The default ID
By default, if no
_id
fields are provided in any inserted document, it will be automatically generated and set as a string UUID (not an actual UUID type).You can modify this behavior by changing the CollectionDefinition.defaultId type when creating the collection; this allows it to generate a UUID or ObjectId instead of a string UUID.
See