Atomic Updates¶
Django’s support for updates
(using the update()
method)
can be used to run atomic updates against a single or multiple documents:
Post.objects.filter(...).update(title='Everything is the same')
results in a update()
query that uses the
atomic $set
operator to update the title field:
.update(..., {'$set': {'title': 'Everything is the same'}})
It’s also possible to use F() objects which are
translated into $inc
operations. For example,
Post.objects.filter(...).update(visits=F('visits')+1)
is translated to:
.update(..., {'$inc': {'visits': 1}})