For AI agents: a documentation index is available at https://www.mongodb.com/pt-br/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
See how MongoDB 9.0 delivers up to 2x higher throughput.
MongoDB Branding Shape
Register now >
Docs Menu

MongoDB\BulkWriteResult::getUpsertedIds()

MongoDB\BulkWriteResult::getUpsertedIds()

Return a map of IDs (i.e. _id field values) for documents that were upserted by all update and replace operations in the bulk write.

function getUpsertedIds(): array

A map of IDs (i.e. _id field values) for documents that were upserted by all update and replace operations in the bulk write.

The index of each ID in the map corresponds to each document's position in the bulk operation. If a document had an ID prior to upserting (i.e. the server did not generate an ID), the index will contain its _id field value. Any server-generated ID will be a MongoDB\BSON\ObjectId instance.

MongoDB\Exception\BadMethodCallException if this method is called and the write operation used an unacknowledged write concern.