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

[MongoDB EventStore] Store strings that "look" like ObjectId as ObjectId #149

Open
alex-laycalvert opened this issue Dec 14, 2024 · 1 comment
Labels
enhancement New feature or request mongodb typing

Comments

@alex-laycalvert
Copy link
Collaborator

MongoDB has this fun quirk that ObjectIds are not comparable to string types when attempting aggregations. This is easy enough to fix when passing ID values directly to queries, I normally use a function to convert all ObjectId string types to real ObjectId type.

However, when the type is saved as a string and not an ObjectId, it's not obvious why comparing ID values within a doc (from events or projections), doesn't return any docs even though the actual string values are the same, but they aren't the right type.

I'm fixing this right now by making sure in aggregations to pass { $toObjectId: '$myProperty' }, but I think we could make this more convenient by storing them as real ObjectId values when storing in MongoDB.

@oskardudycz
Copy link
Collaborator

@alex-laycalvert sounds fair, but it'd be worth researching how others are handling it. The challenge that we may be facing are false positives. See the issue about (de)serialising BigInts: event-driven-io/Pongo#98

@oskardudycz oskardudycz added typing mongodb enhancement New feature or request labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mongodb typing
Projects
None yet
Development

No branches or pull requests

2 participants