gpt4 book ai didi

php - 使用php在mongodb中的数组(集合)中的数组中推送数组

转载 作者:可可西里 更新时间:2023-11-01 09:45:24 24 4
gpt4 key购买 nike

我在 MongoDB 中有一个名为 job 的集合

    Job{
_id : ‘12344’,
cust_id: 'cust1',
title: 'Create Website',
description: 'We require it in 2 weeks only',
location: 'japan',
images:{
'image1',
'image2',
'image3'
},
video:{
'video1',
'video2'
},
budget:'15000',
duration:'2 weeks',
Proposals:[{
"sender_id" => "5",
"description" =>"I can do your task before 2 week",
"date" => "2013-08-05"
},
{
"sender_id" => "6",
"description" =>"I can do your task in 2 week, with best quality",
"date" => "2013-08-05"

}
]
}

我想在 sender_id=5 的提案属性中添加消息,如下所示;

Job{
_id : ‘12344’,
cust_id: 'cust1',
title: 'Create Website',
description: 'We require it in 2 weeks only',
location: 'japan',
images:{
'image1',
'image2',
'image3'
},
video:{
'video1',
'video2'
},
budget:'15000',
duration:'2 weeks',
Proposals:[{
"sender_id" => "5",
"description" =>"I can do your task before 2 week",
"date" => "2013-08-05"
“messages”:[{
"message_sender" :"Can we meet",
"date" : "2013-08-06"
}
]
},
{
"sender_id" => "6",
"description" =>"I can do your task in 2 week, with best quality",
"date" => "2013-08-05"

}
]
}

我的文档是,

$document = array( 
"message_sender" =>"Can we meet",
"date" => "2013-08-06"
);

我真的很难做这件事。这是将消息添加到提案数组。有关于 PHP 代码的帮助吗?

最佳答案

这对我来说是完美的答案,

db.jobs.update({"_id" : "12344","Proposals.sender_id":"5"},{$push:{"Proposals.$.messages" : { "message" : "Can we meet" , "date":"2013-08-06"}}})

关于php - 使用php在mongodb中的数组(集合)中的数组中推送数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18118961/

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