Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Method #831

Merged
merged 2 commits into from Jan 24, 2024
Merged

Sync Method #831

merged 2 commits into from Jan 24, 2024

Conversation

roman-right
Copy link
Member

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)

@roman-right roman-right merged commit 7c49b91 into main Jan 24, 2024
21 checks passed
@roman-right roman-right deleted the feature/sync branch January 24, 2024 21:41
@roman-right roman-right mentioned this pull request Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant