Answer the question
In order to leave comments, you need to log in
How to add multiple arrays at once to a MongoDB document using PHP?
I want to add 2 arrays to the Mongo DB database at once.
In order to add 1 array to the phone array, I used the command:
$col->update(array("email"=>$email), array('$addToSet'=>array("phone" => array("id" => "3","no" => "+1 000 0000","name" => "Bob"))));
"_id": "id",
"email": "[email protected]",
"phone": [
{
"id": "1",
"name": "Bob",
"no": "+1 000 0000",
},
{
"id": "2",
"name": "Bob",
"no": "+1 000 0000",
}
]
$col->update(array("email"=>$email), array('$addToSet'=>array("phone" => array(("id" => "6","name" => "Bob","no" => "+1 000 0000"),("id" => "7","name" => "Bob","no" => "+1 000 0000")))));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question