Update
Bulk Write
MongoDB lets you perform Bulk Write operations using bulk_write. Perform Bulk writes as follows.
class BulkWrite:
def __init__(self,
ordered=True):
Arguments
| Argument | Type | Description |
|---|---|---|
ordered | boolean | Perform the write operations either in order or arbitrarily. |
Example
from djongo import BulkWrite
with BulkWrite():
entry = Entry.objects.get(pk=p_key) # Queries the DB once
entry.headline = 'The Beatles reconcile'
entry.save() # Djongo does not really do a update to MongoDB
Entry.objects.create(name='How the beatles reconciled') # Djongo does not really do a insert to MongoDB
# On exit, does: db.entry.bulk_write([UpdateOne(), InsertOne()])
Unordered Bulk Writes
Example
from djongo import BulkWrite
with BulkWrite(ordered=False):
entry = Entry.objects.get(pk=p_key) # Queries the DB once
entry.headline = 'The Beatles reconcile'
entry.save() # Djongo does not really do a update to MongoDB
Entry.objects.create(name='How the beatles reconciled') # Djongo does not really do a insert to MongoDB
# On exit, does:
# db.entry.bulk_write(
# [UpdateOne(), InsertOne()]
# ordered=False)
