gpt4 book ai didi

php - mongodb-php 更新 $pull

转载 作者:可可西里 更新时间:2023-11-01 10:06:54 26 4
gpt4 key购买 nike

有一个集合“emailDeliveryActive”:

{
"_id": ObjectId("4f1950f0e902edfc3e000001"),
"coupons": {
"4f1950b7e902edf23e000001": {
"_id": ObjectId("4f1950b7e902edf23e000001"),
"couponID": ObjectId("4f15c7d8e902edb667000000")
},
"4f1950bfe902ed843f000000": {
"_id": ObjectId("4f1950bfe902ed843f000000"),
"couponID": ObjectId("4f171f33e902ed4f4f000002")
}
},
"recipients": [
{
"email": "test1@gmail.com",
"get": "?auth=ZG1pdHJ5LnZvbG9zbmloaW5AZ21haWwuY29tfDA5OGY2YmNkNDYyMWQzNzNjYWRlNGU4MzI2MjdiNGY2"
},
{
"email": "test2@gmail.com",
"get": "?auth=ZGpyb3VibGVAZ21haWwuY29tfDA5OGY2YmNkNDYyMWQzNzNjYWRlNGU4MzI2MjdiNGY2"
},
{
"email": "test3@gmail.com",
"get": "?auth=a2FsaWJyb3YxQGdtYWlsLmNvbXwwOThmNmJjZDQ2MjFkMzczY2FkZTRlODMyNjI3YjRmNg=="
}
],
"title": "test"
}

必须来自一组“收件人”才能从给定电子邮件中删除项目。这样做:

$result = $mongoDB->emailDeliveryActive->update(
array('_id' => $emailDelivery['_id']),
array(
'$pull'=>array(
'recipients.$.email' => 'test1@gmail.com'
)
)
);

$result 为 TRUE,但集合不变。我做错了什么?

最佳答案

您不需要 $ 运算符 - 它用于“查询中匹配数组项的位置” - 在这里使用没有意义。尝试:

 $result = $mongoDB->emailDeliveryActive->update(
array('_id' => $emailDelivery['_id']),
array(
'$pull'=> array('recipients' => array('email' => 'test1@gmail.com'))
)
);

关于php - mongodb-php 更新 $pull,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8952714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com