Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-2950

floating point representation varies from one way to insert to another ?

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.1
    • Affects Version/s: 1.8.0
    • Component/s: Tools
    • None
    • Environment:
      ubuntu 10.10 64 bits

      Hi,

      i'm facing a problem while trying to store geolocalised points and key / values attached to it. The problem i'm encountering is that i need to check if a given point (identified by a couple lat / long) is already existing in the database or not.
      Depending on the way i'm inserting my geolocalised points (either from pymongo, javascript shell or mongoimport), i get different results.

      For instance, i try to store value 0.7 as a float using each of the 3 ways.

      The results i get are the following :

      { "_id" : ObjectId("4da6e294aea05d721a4a87b9"), "value_from_mongoimport" : 0.7000000000000001 } { "_id" : ObjectId("4da6e2a3e36333098e18d40c"), "value_from shell" : 0.7 } { "_id" : ObjectId("4da6e2aa11f4ac1bc0000000"), "value_from_pymongo" : 0.7 }

      I'm precisely using the "mongoimport way" to store data as it offers better performances than other ways.

      The problem is, at a later time, when i do, from python, somethink like :
      db.testfind_one(

      {"mykey" : 0.7}

      ), i get none ......

      I understand the problem of floating point representation, but why is it only affecting mongoimport ? is this something that implies the json to bson transformation ?

      Help appreciated.

      Regards.

            Assignee:
            aaron Aaron Staple
            Reporter:
            lilou63 olivier barbecot
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: