mongodb php $推送更新与数组

时间:2015-03-30 16:21:50

标签: php mongodb

我有一个像这样结构的mongodb集合:

{
  "_id" : 1,
  "immagini" : {
    "imgid" : ObjectId("551969b426a8a4e00800002b"),
    "title" : "ceccotti",
    "contenttype" : "image/jpeg"
  }
}

我想在阵列中添加其他文档" immagini"我试着这样做:

$filter = array('_id'=>1);
$update = array('$push'=>array('immagini'=>array (
  "imgid" => $id,
  "title" => $title,
  "contenttype"=> $imageType)));
$coll->update($filter,$update);

但是我收到了这个错误:

Uncaught exception 'MongoWriteConcernException' with message 'localhost:27017: The field 'immagini' must be an array but is of type Object in document {_id: 1}' in C:\inetpub\wwwroot\tesi\upload_img_to_array.php:54 Stack trace: #0 C:\inetpub\wwwroot\tesi\upload_img_to_array.php(54): MongoCollection->update(Array, Array) #1 {main} thrown in C:\inetpub\wwwroot\tesi\upload_img_to_array.php on line 54

我做错了什么?

0 个答案:

没有答案