If you wish to apply changes from the database to the document, utilize the sync method:
await bar.sync()
Two merging strategies are available: local and remote.
Remote Merge Strategy
The remote merge strategy replaces the local document with the one from the database, disregarding local changes:
from beanie import MergeStrategy
await bar.sync(merge_strategy=MergeStrategy.remote)
The remote merge strategy is the default.
Local Merge Strategy
The local merge strategy retains changes made locally to the document and updates other fields from the database.
BE CAREFUL: it may raise an ApplyChangesException in case of a merging conflict.
from beanie import MergeStrategy
await bar.sync(merge_strategy=MergeStrategy.local)
Syncing from the Database
If you wish to apply changes from the database to the document, utilize the sync method:
Two merging strategies are available:
local
andremote
.Remote Merge Strategy
The remote merge strategy replaces the local document with the one from the database, disregarding local changes:
The remote merge strategy is the default.
Local Merge Strategy
The local merge strategy retains changes made locally to the document and updates other fields from the database. BE CAREFUL: it may raise an
ApplyChangesException
in case of a merging conflict.