const result = await collection.updateOne({
_id: 'abc'
}, {
$set: { name: 'John' }
}, {
upsert: true
});
if (result.upsertedCount) {
console.log(`Document with ID ${result.upsertedId} was upserted`);
}
matchedCount - The number of documents that matched the filter.
modifiedCount - The number of documents that were actually modified.
upsertedCount - The number of documents that were upserted.
upsertedId - The identifier of the upserted document if upsertedCount > 0
.
Represents the result of an updateMany operation.