Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-430

Integers inside array are converted to float when retrieving a document previously saved with the mongo client

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 12_01_17
    • Affects Version/s: 1.3.1, 1.5.2
    • Component/s: None
    • Environment:
      Mac OS X Snow Leopard, Ubuntu Linux 10.10, CentOS 5.5, Ruby 1.9.2, MongoDB 2.0.3

      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?

            Assignee:
            tyler@10gen.com Tyler Brock
            Reporter:
            vicentemundim Vicente Mundim
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: