const result = await collection.updateOne({
_id: 'abc'
}, {
$set: { name: 'John' }
}, {
upsert: true
});
if (result.upsertedCount) {
console.log(`Record with identifier ${JSON.stringify(result.upsertedId)} was upserted`);
}
matchedCount - The number of records that matched the filter.
modifiedCount - The number of records that were actually modified.
upsertedCount - The number of records that were upserted.
upsertedId - The identifier of the upserted record if upsertedCount > 0
.
Represents the result of a generic
update
command using the Data API.