bobthecow / genghis

The single-file MongoDB admin app
http://genghisapp.com
MIT License
1.45k stars 165 forks source link

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

Open thomas-riccardi opened 9 years ago

thomas-riccardi commented 9 years ago

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 caf6985866020e93fadc594895a1a0ebc4618f60 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 commented 9 years ago

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.