BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.91k stars 201 forks source link

Sync Method #831

Closed roman-right closed 5 months ago

roman-right commented 5 months ago

Syncing from the Database

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)