Mongodb嵌套数组值始终为空

时间:2015-08-18 04:45:46

标签: php mongodb

Mongodb提供以下内容:

{ 
  "_id" : ObjectId("55d1d8ea464498a8338b4567"),
  "appuserfirstname" : "Bhatti", 
  "appuserlastname" : "Singh", 
  "appusermiddlename" : "Tripatpal", 
  "appuseremail" : "tripat.90@gmail.com", 
  "appusergoogleid" : [ 
    { "id" : "APA91bFPqNjK5bWdTe6bAniDV8ZlmG5vL3Q1qRz_WGAasOMu_WBbzoorWI2uCU7yC4IS-yggNGQvL7oUp5YhiejOC1TB4bFQspKj4AUZ05-IEL9DJiI2oNwIl5YwW5zyBVqrTMNWFF2B" }
  ], 
  "usercreationdate" : ISODate("2015-08-17T18:21:54Z"), 
  "status" : "0", 
  "userfollows" : [ 
    { "following" : ObjectId("55cd8dae46449867738b4567") } 
  ] 
}

我想要以下的ID。但它总是给我空字符串

<?php
$appuserid =    '123456789';     
$appuserscollection =   $this->database->createCollection("appusers");
$followers =    array('_id' => new MongoId($appuserid));
$s =    "";          
$result =   $appuserscollection->find($followers);
foreach($result as $document) {
    $s.=$document['userfollows'];
}
echo $s;
?>

1 个答案:

答案 0 :(得分:0)

使用

$appuserscollection = $this->database->createCollection("appusers");

您创建了一个新集合。并且新的集合总是空的

你可以尝试

$collection = new MongoCollection($this->database, 'appusers');