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

Adding DeleteExactKeyStrategy #153

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

Conversation

andrewbelu
Copy link

@andrewbelu andrewbelu commented Mar 15, 2024

Allows for the Mongo filter opreation to be set to the exact key coming from the key doc rather than having a superfluous _id key.

This is needed for a few use cases I can imagine, but the one in particular is when the key doc is inserting into a sharded collection and already has an _id field with another field and the document.id.strategy is set to PartialValueStrategy for inserts/updates. When deleting, I would like to simply directly set the key (as the key already has the required fields) instead of generating an additional _id key that the DeleteOneDefaultStrategy seems to add:

if (idStrategy instanceof DefaultIdFieldStrategy) { deleteFilter = idStrategy.generateId(document, null).asDocument(); } else { deleteFilter = new BsonDocument(ID_FIELD, idStrategy.generateId(document, null)); }

Notice if the ID strategy is anything other than the default ID strategy, the DeleteOneDefaultStrategy adds the ID_FIELD key.

With this, I can now simply specify the delete.writemodel.strategy as DeleteExactKeyStrategy and it will properly format the filter expression.

I could not find any way to get this behaviour out of the current write strategies.

Allows for the Mongo filter opreation to be set to the exact key coming from the key doc rather than having a superfluous _id key.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant