簡體   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