为什么我从 MongoCollection::find 得到一个空数组
Why am I getting an empty array from MongoCollection::find
当我使用以下 PHP 代码时:
$m = new MongoClient();
$db = $m->selectDB('mylocalmap_development');
$collection = new MongoCollection($db, 'stores');
$cursor = $collection->find();
var_dump($cursor); exit;
..我得到一个空数组:
object(MongoCursor)#82 (0) { }
但是如果我执行以下操作,我可以看到该集合中有一条记录:
$ mongo
MongoDB shell version: 2.4.12
connecting to: test
> use mylocalmap_development
switched to db mylocalmap_development
> db.stores.find();
{ "_id" : ObjectId("54aa9626adc9f013088b4567"), "name" : "The Greengrocer", "address" : "123 Fake Street", "city" : "Stirling" }
我做错了什么?无论如何我都在关注文档
尝试iterator_to_array($cursor)
查看光标的内容。如果有记录,则数组不为空:
var_dump(iterator_to_array($cursor));
当我使用以下 PHP 代码时:
$m = new MongoClient();
$db = $m->selectDB('mylocalmap_development');
$collection = new MongoCollection($db, 'stores');
$cursor = $collection->find();
var_dump($cursor); exit;
..我得到一个空数组:
object(MongoCursor)#82 (0) { }
但是如果我执行以下操作,我可以看到该集合中有一条记录:
$ mongo
MongoDB shell version: 2.4.12
connecting to: test
> use mylocalmap_development
switched to db mylocalmap_development
> db.stores.find();
{ "_id" : ObjectId("54aa9626adc9f013088b4567"), "name" : "The Greengrocer", "address" : "123 Fake Street", "city" : "Stirling" }
我做错了什么?无论如何我都在关注文档
尝试iterator_to_array($cursor)
查看光标的内容。如果有记录,则数组不为空:
var_dump(iterator_to_array($cursor));