Mongo php驱动程序工作与错误,在哪里是我的失败


Mongo php driver works with errors, where is my fail?

视频在这里: http://youtu.be/ijqde9SLd3s

我有php代码:http://pastebin.com/Bb9SSQpy我得到了这个print_r空的结果:

    MongoCursor Object

()

我使用这个数据库:http://pastebin.com/vz7M0KDB在mongo控制台中,所有工作正常,这个命令

db.unicorns.find({weight:{$lt:400}})

给我这个结果

{"_id": ObjectId("53d191248f800def0598465b"), "name": "Billy", "gender": "m", "loves": ["banana", "apple"], "weight": 120, "vampires": 14}

控制台截图:http://rghost.ru/57170098.view

我的问题在哪里?为什么print_r游标在php是空的?

是否存在活动连接?默认情况下,它连接到localhost:27017的本地MongoDB实例

有关连接的更多信息,请参阅此页:http://php.net/manual/en/class.mongoclient.php

使用print_r(iterator_to_array(MongoCursor Object));将迭代器转换为数组并输出它,或者使用

对其进行迭代。
foreach(MongoCursor Object as $resultObject) { }

这是因为数据类型,在您的PHP中,您正在查询:

   $cur = $col->find(array(
        'weight' => array (
            '$lt' => '400'
        )
   ));

但是在你的数据库中有:

 weight: 600,

必须按类型查询,去掉字符串部分,按int查询