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

use replaceOne when full document is available #867

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

nimatrueway
Copy link

@nimatrueway nimatrueway commented Mar 16, 2024

Currently in change_stream mode of incremental synchronization, while processing the change stream; in those cases that a FullDocument is available in an "u" (update) or "r" (replace) event; MongoShake modifies it to { $set: event.FullDocument } which later in the writing phase will activate this code path

https://github.com/alibaba/MongoShake/blob/develop/executor/db_writer_bulk.go#L132-L164

meaning an update query will be used to write to the destination database instead of replace. This causes a fatal error as having _id in the event.FullDocument will fail the update query as MongoDB does not allow modification of the immutable _id field. I believe the intended code path when a FullDocument is available is in fact the following

https://github.com/alibaba/MongoShake/blob/develop/executor/db_writer_bulk.go#L166-L182

so it makes sense to simply pass FullDocument as the object to activate the replace code path.

otherwise the update will be attempted per individual fields which is both incorrect and will fail because _id can to be set
@CLAassistant
Copy link

CLAassistant commented Mar 16, 2024

CLA assistant check
All committers have signed the CLA.

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.

3 participants