Represents the result of a generic update* command performed on the Data API.
update*
🚨Important: The exact result type depends on the upsertedCount field of the result:
upsertedCount
0
1
const result = await collection.updateOne( { _id: 'abc' }, { $set: { name: 'John' } }, { upsert: true },);if (result.upsertedCount) { console.log(`Document with ID ${result.upsertedId} was upserted`);} Copy
const result = await collection.updateOne( { _id: 'abc' }, { $set: { name: 'John' } }, { upsert: true },);if (result.upsertedCount) { console.log(`Document with ID ${result.upsertedId} was upserted`);}
Overview
Represents the result of a generic
update*
command performed on the Data API.upsertedCount
is0
, the result will be of type GuaranteedUpdateResult & NoUpsertUpdateResult.upsertedCount
is1
, the result will be of type GuaranteedUpdateResult & UpsertedUpdateResult.