How can I replace multiple documents with only one document?

const result = db.collection.find({name: "abc", status: false});

result gives me lets say 2 documents:

[{name: "abc", status:false, otherProp: "otherProp1"},..., {name: "abc", status: false, otherProp: "otherProp2",...}]

Now I want to replace both documents with:

{name: "abc", status:true, otherProp: "newProp"}

How can I do that? everything I tried, always replaces each document with the new document…

Only way I see is:

An ordered bulkWrite within a optional but safer transaction that

1 - deleteMany {name:abc,status:false}
2 - insertOne the new document

1 Like

Transaction is the way to go if atomicity is desired.