解决
要查看数据,我在光标上做了一个var_dump,你必须先将光标循环到var_dump它。
foreach($user_images as $image) {
var_dump($image)
}
可以在以下网址找到更多相关信息:
http://php.net/manual/en/class.mongocursor.php
/解决
我的MongoDB中有一个名为'user_image'的集合。我使用PHP 5.3和mongoDB db v2.0.5,pdfile版本4.5。我在XAMPP中有这个设置。我只是想找到集合中的所有文档。当我运行下面的信息时,即使我可以在运行db.user_image.find()的终端中确认它返回结果,也没有返回任何内容。
$m = new Mongo();
$db = $m->selectDB('dev_app');
$collection = new MongoCollection($db, 'user_image');
$collection->find();
如果我将查询更改为user_uuid只使用findOne,我会得到一个结果!示例如下:
$collection->findOne(array('user_uuid' => 'de977803-f198-416a-8806-acbc1fa3f718'));
以下是集合user_image中的示例文档:
{
"_id" : ObjectId("500c3f13ab8692ced0d9df6f"),
"user_uuid" : "de977803-f198-416a-8806-acbc1fa3f718",
"image_name" : "4a5e286e101429da0a3c3a576ffa4878.jpg",
"image_url" : "/uploaded_files/files/4a5e286e101429da0a3c3a576ffa4878.jpg",
"sm_thumb_url" : "/uploaded_files/thumbnails/4a5e286e101429da0a3c3a576ffa4878.jpg",
"md_thumb_url" : "/uploaded_files/files/4a5e286e101429da0a3c3a576ffa4878.jpg",
"lg_thumb_url" : "/uploaded_files/files/4a5e286e101429da0a3c3a576ffa4878.jpg",
"status" : "A",
"created" : ISODate("2012-07-22T17:57:36.835Z"),
"modified" : ISODate("2012-07-22T17:57:36.835Z"),
"created_by_uuid" : "de977803-f198-416a-8806-acbc1fa3f718",
"modified_by_uuid" : "de977803-f198-416a-8806-acbc1fa3f718"
}
查找查询中缺少什么?谁能帮我?感谢。
答案 0 :(得分:0)
$cursor = $collection->find();
find()方法将返回一个Cursor对象。
现在,您可以使用toArray()方法获取数据。
$dataArray = $cursor->toArray();
就这么简单。 或使用foreach逐一获取文档。附言FindOne()返回一个数组。
https://www.php.net/manual/en/class.mongodb-driver-cursor.php