2016-06-22 42 views
0

最終的に私は以下のMongoDBオブジェクトからcustomer_idプロパティにアクセスしようとしています。私は、最初の配列に変換することによってこれを行うことができます。PHPでMongoDBオブジェクトのプロパティにアクセスする

$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); 
$filter = [ "customer_id" => ['$eq' => '1001']]; 
$query = new MongoDB\Driver\Query($filter); 
$cursor = $manager->executeQuery('srp.products', $query); 
$cursor = $cursor->toArray(); 
print_r ($cursor[0]->customer_id); 

しかし、私が使用してそれにアクセスすることはできません。

$cursor->cursor['current_doc']->customer_id 

私は常に最初の配列に変換する必要があります、または私は何かが足りないのですか?

MongoDB\Driver\Cursor Object 
 
(
 
    [cursor] => Array 
 
     (
 
      [stamp] => 0 
 
      [is_command] => 
 
      [sent] => 1 
 
      [done] => 
 
      [end_of_event] => 
 
      [in_exhaust] => 
 
      [has_fields] => 
 
      [query] => stdClass Object 
 
       (
 
        [find] => products 
 
        [filter] => stdClass Object 
 
         (
 
          [customer_id] => stdClass Object 
 
           (
 
            [$eq] => 1001 
 
           ) 
 

 
         ) 
 

 
       ) 
 

 
      [fields] => stdClass Object 
 
       (
 
       ) 
 

 
      [read_preference] => Array 
 
       (
 
        [mode] => 1 
 
        [tags] => Array 
 
         (
 
         ) 
 

 
       ) 
 

 
      [flags] => 0 
 
      [skip] => 0 
 
      [limit] => 0 
 
      [count] => 1 
 
      [batch_size] => 0 
 
      [ns] => srp.products 
 
      [current_doc] => stdClass Object 
 
       (
 
        [_id] => MongoDB\BSON\ObjectID Object 
 
         (
 
          [oid] => 576aa3469771c4dbeef44022 
 
         ) 
 

 
        [customer_id] => 1001 
 
        [products] => Array 
 
         (
 
          [0] => 150 
 
          [1] => 160 
 
          [2] => 170 
 
          [3] => 180 
 
         ) 
 

 
       ) 
 

 
     ) 
 

 
    [server_id] => 1 
 
)

答えて

0

はい、あなたが行うあなたのよう->toArray()を呼び出すためにいずれか、またはあなたが結果を得るためにCursorを通じてforeachでき想定しています。 Cursorで入手可能な情報の詳細については、docsをご覧ください。

関連する問題