gpt4 book ai didi

php mongodb 发现不工作

转载 作者:可可西里 更新时间:2023-11-01 09:56:00 25 4
gpt4 key购买 nike

已解决

为了查看数据,我在游标上做了一个 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 = $collection->find(); find() 方法将返回一个 Cursor 对象。现在您可以使用 toArray() 方法来获取数据。$dataArray = $cursor->toArray(); 就这么简单。 或者使用foreach逐个获取文档。附言。 FindOne() 返回一个数组。

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

关于php mongodb 发现不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11603952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com