'Pymongo: update document only if value of a field matches a provided value

Is it possible to update a document based on the condition that the value of a field in that document matches a value that I provide?

I can easily do this in two steps but was wondering if there was a way to do it in a single call to MongoAtlas.



Solution 1:[1]

It is a single step execution. You don't need two steps.

Reference

And Python implementation is same syntax as plain queries.

db.collection.update_one({
  filter condition goes here
},{
  '$set': {
    update fields goes here
  }
}, upsert=False) //Options

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gibbs