繁体   English   中英

php mongodb找不到工作

[英]php mongodb find not working

解决了

要查看数据,我在光标上执行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"
}

我在查询查询中缺少什么? 谁能帮我? 谢谢。

Cursor Object在这里是一个'key'

$cursor = $collection->find(); find()方法将返回一个Cursor对象。 现在您可以使用toArray()方法来获取数据。 $dataArray = $cursor->toArray(); 就那么简单。 或者使用foreach逐个获取文档 PS。 FindOne()返回一个数组。

https://www.php.net/manual/en/class.mongodb-driver-cursor.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM