I want to add 2 arrays in phone array to the Mongo database.
$addToSet and $each show how to add 1n array with objects to another array, but I want to add 2 or more arrays not objects.
To add one array in phone, I used the command:
$col->update(array("email"=>$email), array('$addToSet'=>array("phone" => array("id" => "3","no" => "+1 000 0000","name" => "Bob"))));
Example document
"_id": "id",
"email": "Name@google.com",
"phone": [
{
"id": "1",
"name": "Bob",
"no": "+1 000 0000",
},
{
"id": "2",
"name": "Bob",
"no": "+1 000 0000",
}
]
I tried to add 2 arrays but it did not work
$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")))));
I have a syntax error here when I try to add multiple arrays with objects:
array(("id" => "6","name" => "Bob","no" => "+1 000 0000"),("id" => "7","name" => "Bob","no" => "+1 000 0000"))
How can I remove this syntax error when adding 2 arrays to the database?