Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 从集合中的文档中删除子文档_Mongodb_Mongodb Query_Mongodb Php_Php Mongodb - Fatal编程技术网

Mongodb 从集合中的文档中删除子文档

Mongodb 从集合中的文档中删除子文档,mongodb,mongodb-query,mongodb-php,php-mongodb,Mongodb,Mongodb Query,Mongodb Php,Php Mongodb,我正在尝试从集合中删除子文档。我试过下面几行代码 public function deleteContactDetailsForItsSubDocument() { $this->collection->updateOne( array('_id' => new MongoDB\BSON\ObjectID($this->id)),

我正在尝试从集合中删除子文档。我试过下面几行代码

         public function deleteContactDetailsForItsSubDocument()
{
        $this->collection->updateOne(
                            array('_id' => new MongoDB\BSON\ObjectID($this->id)),
                               array('$pull' => 
                                       array('ContactDetails.ContactTypeId' => $this->ContactTypeId)
                                     ));
}                
它抛出错误消息“Uncaught exception'MongoDB\Driver\exception\BulkWriteException”,消息为“无法使用(ContactDetails.ContactTypeId)的部分(ContactTypeId)遍历元素”

集合中的文档如下所示

      {
      "_id": ObjectId("5a8d47d8d2ccda11fc004d91"),
      "EmployeeNumber": "9883456787",
      "FirstName": "Sana",
      ...
      "ContactDetails": [
      {
        "ContactTypeId": "04596c6f-82e6-8f00-e3a9-1f3199894284",
        "ContactType": "Phone",
        "ContactTypeValue": "99456789756" 
     },
     {
        "ContactTypeId": "71d0152c-293f-4c6f-2360-bbdfe368eacb", 
        "ContactType": "Phone",
        "ContactTypeValue": "9894567890" 
     } 
   ] 
   ...
试试这个:

$this->collection->updateOne(
                   array('_id' => new MongoDB\BSON\ObjectID($this->id)),
                   array('$pull' => 
                       array('ContactDetails' =>
                           array('ContactTypeId' => $this->ContactTypeId)
                       )
                   )
);
可能重复的