I've run into this issue in production after running some scripts with the mongo client to update documents. Here are the steps to reproduce this error:
Start an IRB session:
> db = Mongo::Connection.new.db("mydb") > coll = db['test'] > coll.insert({:name => 'bar', :age => 123, :ids => [1, 2, 3]}) => BSON::ObjectId('4f6cc539edfae764e7000001') > coll.find_one({:name => 'bar'}) => {"_id"=>BSON::ObjectId('4f6cc539edfae764e7000001'), "name"=>"bar", "age"=>123, "ids"=>[1, 2, 3]}
So far, so good. Now we run the mongo client (/usr/bin/mongo):
> use mydb switched to db mydb > doc = db.test.findOne({name: 'bar'}) { "_id" : ObjectId("4f6cc539edfae764e7000001"), "name" : "bar", "age" : 123, "ids" : [ 1, 2, 3 ] } > db.test.save(doc) > db.test.findOne({name: 'bar'}) { "_id" : ObjectId("4f6cc539edfae764e7000001"), "name" : "bar", "age" : 123, "ids" : [ 1, 2, 3 ] }
As you can see everything seems fine. But now returning to the IRB session:
> coll.find_one({:name => 'bar'}) => {"_id"=>BSON::ObjectId('4f6cc539edfae764e7000001'), "name"=>"bar", "age"=>123, "ids"=>[1.0, 2.0, 3.0]}
Now the document ids field has been returned with floats instead of integers. This happens even when just running a update on a document in the mongo client.
Is this related to the ruby driver or is it related to the mongo client not displaying the array of integers properly?
What is funny is that you can query for both the integer value or the float value and it still returns the document:
> coll.find_one({:ids => 1}) => {"_id"=>BSON::ObjectId('4f6cc539edfae764e7000001'), "name"=>"bar", "age"=>123, "ids"=>[1.0, 2.0, 3.0]} > coll.find_one({:ids => 1.0}) => {"_id"=>BSON::ObjectId('4f6cc539edfae764e7000001'), "name"=>"bar", "age"=>123, "ids"=>[1.0, 2.0, 3.0]}
Any thoughts?
- depends on
-
SERVER-5424 Shell doesn't re-save retrieved integers in an array as integers (converted to 64-bit float)
- Backlog