Hi i am new to mongodb and i am using PHP here. I want to update the sub-document with an array like below to existing document.
[weeksAtOne] => Array
(
[156] => 1586
)
when i try to call the below functions
$query = array('decade' => array('$in' => array(1980,1990)));
$songs->update($query,
array('$push'=>array('weeksAtOne'=>array(156 => 500))),
array('safe'=>true,'timeout'=>5000,'multiple'=>true))
It is not coming as expected instead it will coming differently. Could you please someone guide me which is the right way to update this.
Original Array:
Array
(
[_id] => MongoId Object
(
[$id] => 55004cbd30d6d48819000004
)
[decade] => 1980
[artist] => Olivia Newton-John
[song] => Physical
[weeksAtOne] => Array
(
[10] => 10
[11] => 100
[22] => 500
)
)
Array
(
[_id] => MongoId Object
(
[$id] => 55004cbd30d6d48819000005
)
[decade] => 1990
[artist] => Mariah Carey
[song] => One Sweet Day
[weeksAtOne] => Array
(
[10] => 16
[21] => 100
[23] => 500
)
)
Expected Output:
Array
(
[_id] => MongoId Object
(
[$id] => 55004cbd30d6d48819000004
)
[decade] => 1980
[artist] => Olivia Newton-John
[song] => Physical
[weeksAtOne] => Array
(
[10] => 10
[11] => 100
[22] => 500
[156] => 1586
)
)
Array
(
[_id] => MongoId Object
(
[$id] => 55004cbd30d6d48819000005
)
[decade] => 1990
[artist] => Mariah Carey
[song] => One Sweet Day
[weeksAtOne] => Array
(
[10] => 16
[21] => 100
[23] => 500
[156] => 1586
)
)