āš”$upsert

Name
Usage Type
Description

$upsert

Boolean

$upsert Operator Will Create Operators Like FindOneAndUpdate If The Entered Data Doesn't Exist

/* Example Usage */
const model = ...Someone Model

(async () => {

await model.findOneAndUpdate({ classNumber: 999 },{ $set:{ name: "Five", surname: "So Beş" } },{ $upsert: true });
/*
{id:3, name: 'Five', surname: 'So Beş', age: null, classNumber: 999, achievements:[]},
*/

})();

Last updated