有一个集合“emaildeliveryactive”:
{
"_id": ObjectId("4f1950f0e902edfc3e000001"),
"coupons": {
"4f1950b7e902edf23e000001": {
"_id": ObjectId("4f1950b7e902edf23e000001"),
"couponID": ObjectId("4f15c7d8e902edb667000000")
},
"4f1950bfe902ed843f000000": {
"_id": ObjectId("4f1950bfe902ed843f000000"),
"couponID": ObjectId("4f171f33e902ed4f4f000002")
}
},
"recipients": [
{
"email": "[email protected]",
"get": "?auth=ZG1pdHJ5LnZvbG9zbmloaW5AZ21haWwuY29tfDA5OGY2YmNkNDYyMWQzNzNjYWRlNGU4MzI2MjdiNGY2"
},
{
"email": "[email protected]",
"get": "?auth=ZGpyb3VibGVAZ21haWwuY29tfDA5OGY2YmNkNDYyMWQzNzNjYWRlNGU4MzI2MjdiNGY2"
},
{
"email": "[email protected]",
"get": "?auth=a2FsaWJyb3YxQGdtYWlsLmNvbXwwOThmNmJjZDQ2MjFkMzczY2FkZTRlODMyNjI3YjRmNg=="
}
],
"title": "test"
}
必须来自“收件人”数组才能从给定电子邮件中删除项目。
这样做:
$result = $mongoDB->emailDeliveryActive->update(
array('_id' => $emailDelivery['_id']),
array(
'$pull'=>array(
'recipients.$.email' => '[email protected]'
)
)
);
$结果为true,但集合不变。我做错什么了?
最佳答案
您不需要$operator,它是用于“查询中匹配数组项的位置”的,在这里使用没有意义。尝试身份:
$result = $mongoDB->emailDeliveryActive->update(
array('_id' => $emailDelivery['_id']),
array(
'$pull'=> array('recipients' => array('email' => '[email protected]'))
)
);
关于php - mongodb-php更新$ pull,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8952714/