const result = await collection.replaceOne({
_id: 'abc'
}, {
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
.
Collection.replaceOne
Represents the result of a replaceOne operation.