$upsert
Insert a new record or update an existing record in the table based on the provided conditions. The $upsert method ensures that if a matching record exists, it will be updated; otherwise, a new record will be created. This method is useful for operations where you want to ensure data consistency without performing separate insert and update queries.
Query
Parameter's
var updateOrCreate = await Member.$upsert({
$where: {
badges: {
$in: [['verified']]
}
},
$update: {
$set: {
badges: ['Special']
}
},
$options: {
$multi: false
},
$rules: {
badges: {
$required: true
}
}
});
Last updated