Articles → MONGODB → Upsert In Mongodb
Upsert In Mongodb
Purpose
Syntax
db.collection.update(
<query>,
<update>,
{
upsert: true
}
)
Example
db.mycollection.updateOne({ name: 'John Doe' }, { $set: { age: 70 } }, { upsert: true })
db.mycollection.updateOne({ name: 'John Doe1' }, { $set: { age: 70 } }, { upsert: true })
Posted By - | Karan Gupta |
|
Posted On - | Wednesday, March 27, 2024 |