Answer the question
In order to leave comments, you need to log in
How to update a record in mongodb given a unique parameter?
Hello. There is an entry in mongodb
{
"_id" : ObjectId("599aa4467745ffb9644da8eb"),
"email" : "[email protected]",
"series" : [
{
"id" : "58e52c4e89673a7a83438f1c",
"letters" : [
{
"id" : "1bki584500r0trtyie7700001",
"sented_at" : [
"2017-08-23 16:45"
]
}
]
}
]
}
"series" : [
{
"id" : "58e52c4e89673a7a83438f1c",
"letters" : [
{
"id" : "1bki584500r0trtyie7700001",
"sented_at" : [
"2017-08-23 16:45"
]
},
{
"id" : "1bki584500r0trtyie7700222",
"sented_at" : [
"2017-08-23 18:22"
]
}
]
}
]
$update = [
"id" => "58e52c4e89673a7a83438f1c",
"letters" => [
[
"id" => "1bki584500r0trtyie77000022",
"sented_at" => [
"2017-08-23 16:45"
]
]
]
];
$contacts->where(['email' => '[email protected]'])->push(["series" => $update]);
Answer the question
In order to leave comments, you need to log in
You need to update with $addToSet.
db.getCollection('t1').update(
{
_id: ObjectId("599aa4467745ffb9644da8eb"),
"series.id": "58e52c4e89673a7a83438f1c",
},
{ $addToSet: {
'series.$.letters': {
"id" : "1bki584500r0trtyie7700002",
"sented_at" : [
"2017-08-23 16:46"
]
}
}
}
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question