2017-01-21 59 views
1

我有一个MongoDB PHP库的问题。我试图在集合中找到某些东西,但得到这个错误。PHP Mongo库溢出检测

Fatal error: 
Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Integer overflow detected on your platform: 1484960424767 in C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php:222 
Stack trace: 
#0 C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php(222): MongoDB\Driver\Cursor->setTypeMap(Array) 
#1 C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\FindOne.php(105): MongoDB\Operation\Find->execute(Object(MongoDB\Driver\Server)) 
#2 C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Collection.php(559): MongoDB\Operation\FindOne->execute(Object(MongoDB\Driver\Server)) 
#3 C:\xampp\htdocs\gameid\index.php(7): MongoDB\Collection->findOne(Array) 
#4 {main} Next MongoDB\Driver\Exception\InvalidArgumentException: Integer overflow detected on your platform: 1484960529934 in C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php:222 
Stack trace: 
#0 C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php(222): MongoDB\Driver\Cursor->setTypeMap(Array) 
#1 C:\ in C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php on line 222 

这里是我的源代码:

$con = new MongoDB\Client('mongodb://user:[email protected]:port/ripes'); 
$con = $con->ripes->games; 

$result = $con->findOne(['gameID' => 'KUDl-xvjWkPJkjTRf-']); 

有什么不对?如果该条目不存在,则PHP不会报告任何错误。

+0

您的数据库实例中是否包含大量项目? – Farkie

+0

在DB中只有一个项目 – Markus

回答

0

我刚刚遇到过整数溢出 PHP异常。看看又您的错误信息,它告诉你到底是什么原因造成的除外:

Integer overflow detected on your platform: 1484960424767 

我能够使用Robo3T(RoboMongo)查看有关的文件,看看引起此值的字段例外(你的情况为1484960424767)。在MongoDB文档中,该字段被定义为NumberLong()类型,并且该值超过了PHP在您使用的版本上解析长整数的能力......最有可能的是32位PHP。如果可能,请尝试使用64位PHP。

在我的情况下,文档字段应该是一个字符串,所以我不得不修改文档创建脚本以强制该值为字符串类型。

$doc = array(
      "field" => (string)$long_number_value 
      );