我正在尝试从集合中删除子文档。我试过下面的代码行
public function deleteContactDetailsForItsSubDocument()
{
$this->collection->updateOne(
array('_id' => new MongoDB\BSON\ObjectID($this->id)),
array('$pull' =>
array('ContactDetails.ContactTypeId' => $this->ContactTypeId)
));
}
它抛出错误消息“未捕获的异常 '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"
}
]
...