Mesut
Mesut

Reputation: 1875

Can we use upsert with update pipeline?

Can we use {upsert: true} for mongoDB update aggregation pipeline? Any examples would be very appreciated.

Upvotes: 1

Views: 432

Answers (1)

hhharsha36
hhharsha36

Reputation: 3349

Yes, of course, it will work.

db.getCollection('tmp5').update({
    "someKey":"nonExisting"
}, [
    {
        "$set": {
            "name": "ValToUpdate"
        }
    }
], {
    upsert: true
})

Mongo Playground Sample

Upvotes: 1

Related Questions