Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Number type changes when editing another field in a document #205

Open
thomas-riccardi opened this issue May 12, 2015 · 1 comment
Open

Comments

@thomas-riccardi
Copy link

genghis tries to find the "best" BSON representation: for small int it will use Int32. This is an issue when number type matters (c++ client, where the exact BSON type must be used when reading a BSON, no implicit casts between number representations): genghisapp will change the type of a field when any other edit happens on the document, for example a Int64 will be saved back as Int32.

Since #142 we can force the Int64 type via NumberLong(), but it's not released yet (when will it be?), and the comment of the commit caf6985 says it cannot know which was the original type (but now ruby mongo client 2.0 is released, so it could be fixed).

Also, to guarantee that no type is changed, support for NumberInt will be required, as mongo shell does, and the default type should be float (or introduce a Float keyword, which doesn't exist in mongo shell because it defaults to float).
(mongo shell is inconsistent because it doesn't displays NumberInt: float and int32 are indistinguishable when printed: this cannot be tolerated on genghis because it would lead to type changes, because what is displayed is what is saved).

@bobthecow
Copy link
Owner

Yes, this is definitely a limitation of Genghis, and just about anything that uses Mongo drivers in non-strictly typed language, really. Or even the Mongo shell, as you've seen.

I've got several ideas about good ways to make it all work in Genghis, but it's not going to be trivial. I'll also try to get an update out which uses v2 of the ruby driver to make it a bit better. In the meantime, you can always use atomic update operators to avoid touching fields with numbers in them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants