I’ve been having trouble trying to update values inside a nested array. My data structure is as follows.
{
"_id" : ObjectId("616e840755595c5d353a1eb3"),
"User" : "Aaron *******",
"Email Address" : "************@outlook.com",
"Password" : "*********************************************************",
"gender" : "male",
"phone" : "*********",
"dob" : "1972-08-09",
"MBTI" : "{\"I\":45,\"N\":20,\"T\":25,\"P\":65}",
"jobs" : {
"a1" : 0,
"a3" : 0,
"a18" : 0,
"a19" : 0,
"a25" : 0,
"a35" : 0,
"a36" : 0,
"a48" : 0,
"a52" : 0
},
"HC" : "[\"C\",\"R\",\"I\"]"
}
I have been using the following code to attempt to update values inside the nested jobs array.
$userdata = (new MongoDB\Client)->kalgu->userdata;
$user = $userdata->findOne(array('Email Address'=> $email));
$updateResult = $userdata->updateOne(
['_id' => $user['_id']],
['set' => [$user['jobs'].$career=>$new]]
);
This results in the following error - Fatal error: Uncaught Error: Object of class MongoDB\Model\BSONDocument could not be converted to string.
Can someone please tell me what I’m doing wrong?