'Updating and pushing an array to mongo collection
Hello all I am trying to create a query in order to update user's by adding another product in MongoDB.
The structure of the table orders is:
{
"username": "mike",
"products": [
{
"_id": {
"$oid": "61f14c42855800006f003062"
},
"number": "3",
"name": "Honduras",
"price": 7,
"stock": 10
}
],
"status": "UNPAID"
}
My query in PHP code is the following:
$collection -> updateOne(
"username"=>"$username",'$push'=>["products" => "$json"]
);
But I get the same error everytime:
Parse error: syntax error, unexpected token "=>", expecting ")"
Any suggestions?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
