mongodb - mongo db add / update array in document with mongo php
Get the solution ↓↓↓I hope someone here can help. I am having trouble targeting a single object in a complex array for update. I provide all fields for the object changed or not but I cannot get an update to work I have used $push to create the multiple objects which seems to work fine, but if I try to update one of them with $set I end up just one object in the array with all the values in it. It may well be that my structure is incorrect and I can change if necessary
The relevant part of the document is
{
"_id" : ObjectId("604b699228b6a51f7d6a4292"),
"settings" : [
{
"default" : {
"filters" : {
"type_id" : "getwin_over15",
"type_name" : "Over 1.5",
"sport_id" : "1",
"sport_name" : "Soccer",
"league_id" : 0,
"league_name" : "All Leagues",
"teama_id" : 0,
"teama_name" : "Team A",
"teamb_id" : 0,
"teamb_name" : "Team B",
"threshold_id" : 75,
"threshold_name" : "75%",
"inby" : "by",
"inbypd" : 5,
"mode" : "Profiles",
"histmatches" : "2"
},
"trading" : {
"price" : "222",
"stake" : "3355",
"matched" : "0",
"back_lay" : "back",
"allowed_time_min" : "5.00",
"allowed_time_max" : "90.00",
"inplay" : {
"attacks" : {
"homeaway" : "home",
"min" : "6123343",
"max" : "5333",
"dispname" : "Attacks"
},
"dattacks" : {
"homeaway" : "away",
"min" : "1",
"max" : "2",
"dispname" : "Dangerous Attacks"
},
"yellowcards" : {
"homeaway" : "both",
"min" : "1",
"max" : "6",
"dispname" : "Yellow Cards"
}
}
}
}
},
{
"new_prof" : {
"filters" : {
"type_id" : "getwin_over15",
"type_name" : "Over 1.5",
"sport_id" : "1",
"sport_name" : "Soccer",
"league_id" : 0,
"league_name" : "All Leagues",
"teama_id" : 0,
"teama_name" : "Team A",
"teamb_id" : 0,
"teamb_name" : "Team B",
"threshold_id" : 75,
"threshold_name" : "75%",
"inby" : "by",
"inbypd" : 5,
"mode" : "Profiles",
"histmatches" : "2"
},
"trading" : {
"price" : "222",
"stake" : "3355",
"matched" : "0",
"back_lay" : "back",
"allowed_time_min" : "5.00",
"allowed_time_max" : "90.00",
"inplay" : {
"attacks" : {
"homeaway" : "home",
"min" : "6123343",
"max" : "5333",
"dispname" : "Attacks"
},
"dattacks" : {
"homeaway" : "away",
"min" : "1",
"max" : "2",
"dispname" : "Dangerous Attacks"
},
"yellowcards" : {
"homeaway" : "both",
"min" : "1",
"max" : "6",
"dispname" : Yellow Cards"
}
}
}
}
}
]
}
I need to target 'default' or 'new_prof' or others and will be providing all the subfields for the update, to overwrite what is there but only for the selected object
I have not managed to construct a $set that will do what I need.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: port 80 in use by "unable to open process" with pid 4!
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.