how to setting the field using Session Variables in $set to Update a Single MongoDB Document in PHP

I'm beginner in php and this is my first time posting a comment.

In MongoDB how do you use Session variable in $set to update a value?

For example, consider a collection school with the following document:

{
    "_id": {
        "$oid": "5fb5a71fc930cc7b988b20ca"
    },
    "SchoolsState": "JOHOR",
    "SchoolsName": "KOLEJ TINGKATAN ENAM PONTIAN",
    "SchoolsCity": "PONTIAN",
    "SchoolsPhoneNo": "11",

}

I want to do something like the below to update where the SchoolsName == $_SESSION["loggeduser_schoolName"], then change the SchoolsPhoneNo:

if (isset($_POST['EditSchoolFormSubmit'])) 
{
  $varSchoolsPhoneNo= $_POST['txtSchoolsPhoneNo'];
  $schoolname = $_SESSION["loggeduser_schoolName"];

  $GoNGetzSmartSchoolFrontEndConnectionString="mongodb://admin:******";
  $GoNGetzSmartSchoolFrontEnd= new MongoDB\Driver\Manager($GoNGetzSmartSchoolFrontEndConnectionString);
  $bulk = new MongoDB\Driver\BulkWrite(['ordered' => true]);
  $bulk->update(['SchoolsName'=> $schoolname],
                ['$set' => ['SchoolsPhoneNo'=>$varSchoolsPhoneNo]],
                ['upsert' => true]
               );
.
.
.

I have tried using this command

  $bulk->update(['SchoolsName'=>'KOLEJ TINGKATAN ENAM PONTIAN'],
                ['$set' => ['SchoolsPhoneNo'=>$varSchoolsPhoneNo]],
                ['upsert' => true]
               );

it worked very well, but if I use session.. there is no change at all.

Answer

Solution:

i found the solution .Just need to add strval.

$schoolname = strval($_SESSION["loggeduser_schoolName"]); 

Source