iwind / rockmongo

RockMongo is a MongoDB administration tool, written in PHP 5.
http://rockmongo.com
Other
1.05k stars 407 forks source link

showing wrong double/float values when query type is php #92

Open GurjinderSingh opened 10 years ago

GurjinderSingh commented 10 years ago

i m inserting some numeric values in db. when i check them in rockmongo they totally different but when i access them from php/mongo shell they are fine.

Update 1 : installed new from git hub but problem is same Update 2 : found the location where data is changing for float its var_export function of php https://github.com/iwind/rockmongo/blob/c7e1f42f764cde03b1147b96d7926c10994334c3/app/classes/VarExportor.php#L48

http://php.net/manual/en/function.var-export.php#113770

test php file

<?php  
$DB_con = new \MongoClient();
$DB_db = $DB_con->selectDB('mydb');
$DB_col = $DB_db->selectCollection('col');
$DB_col->insert(array('1'=>  2.4,
    '2'=>  1.3,
    '3'=>  1.7,
    '4'=> 0.2,
    '5'=> 1.1,
    '6'=> 1.3,
    '7'=> 1.0,
    '8'=> 1.5,
    '9'=> 1.7,
    '10'=> 1.9,
    '11'=> 2.3,
    '12'=> 2.39,
    '13'=> 2.40,
    '14'=> (double)2.41,
    '14-1'=> (double)2,
    '15'=> (float)2.41,
    '15-1'=> (float)2,
    ));
?>

test find code change id please

<php
var_dump($DB_col->findOne(array ('_id' => new \MongoId("542009ac92dd951d5c8b4567"))));
?>

output ::

array(18) {
  ["_id"]=>
  object(MongoId)#7 (1) {
    ["$id"]=>
    string(24) "5420102292dd95135d8b4567"
  }
  [1]=>
  float(2.4)
  [2]=>
  float(1.3)
  [3]=>
  float(1.7)
  [4]=>
  float(0.2)
  [5]=>
  float(1.1)
  [6]=>
  float(1.3)
  [7]=>
  float(1)
  [8]=>
  float(1.5)
  [9]=>
  float(1.7)
  [10]=>
  float(1.9)
  [11]=>
  float(2.3)
  [12]=>
  float(2.39)
  [13]=>
  float(2.4)
  [14]=>
  float(2.41)
  ["14-1"]=>
  float(2)
  [15]=>
  float(2.41)
  ["15-1"]=>
  float(2)
}

find output in mongo shell

mydb.col.find( { '_id':ObjectId("54200c5092dd95a85c8b4567")});

{ "_id" : ObjectId("54200c5092dd95a85c8b4567"), "1" : 2.4, "2" : 1.3, "3" : 1.7, "4" : 0.2, "5" : 1.1, "6" : 1.3, "7" : 1, "8" : 1.5, "9" : 1.7, "10" : 1.9, "11" : 2.3, "12" : 2.39, "13" : 2.4, "14" : 2.41, "14-1" : 2, "15" : 2.41, "15-1" : 2 }

output in rock mongo query type php

 array (
  '_id' => new MongoId("54200c5092dd95a85c8b4567"),
  1 => 2.3999999999999999,
  2 => 1.3,
  3 => 1.7,
  4 => 0.20000000000000001,
  5 => 1.1000000000000001,
  6 => 1.3,
  7 => 1,
  8 => 1.5,
  9 => 1.7,
  10 => 1.8999999999999999,
  11 => 2.2999999999999998,
  12 => 2.3900000000000001,
  13 => 2.3999999999999999,
  14 => 2.4100000000000001,
  '14-1' => 2,
  15 => 2.4100000000000001,
  '15-1' => 2,
)

output in rock mongo query type JSON

{
   "_id": ObjectId("54200c5092dd95a85c8b4567"),
   "1": 2.4,
   "2": 1.3,
   "3": 1.7,
   "4": 0.2,
   "5": 1.1,
   "6": 1.3,
   "7": 1,
   "8": 1.5,
   "9": 1.7,
   "10": 1.9,
   "11": 2.3,
   "12": 2.39,
   "13": 2.4,
   "14": 2.41,
   "14-1": 2,
   "15": 2.41,
   "15-1": 2
}