Q:

Writing a php file to add a document to mongoDB collection

Below is my recordSigfox.php file. For now I am testing it from the addess bar:
http://...server.../recordSigfox.php?data=e049d3c02b7f5542
Tested separately and working:
-The first part connects to mongoDB and creates a testData collection. 
-The second part decodes the hex message into its original components, a latitude and a longitude. I WANT TO RECORD THESE in testData.
-The third part just lists the contents of testData.
Apparent issue code:
  $document = array(
          "Latitude" => $lt,
          "Longitude" => $lg,
        );    
        $manager->$collection->insert($document);

Full code:
<html>
  <head>
   <title>Unpack</title>
  </head>
  <body>
<?php
    //connect to DB
    $user = "muntean";
    require '/var/composer/vendor/autoload.php';
    $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
    echo "Connection to database successfully";
    $collection = new MongoDB\Collection($manager, $user, 'testData');

    //get data from the address bar: e049d3c02b7f5542
    $_data = $_GET["data"];
    $coord = unpack('flat/flon', pack('H*', $_data));
    $lt = $coord['lat'];
    $lg = $coord['lon'];
    //echo lt shows: -6.6027679443359
    //echo lg shows: 53.374187469482

    $document = array(
      "Latitude" => $lt,
      "Longitude" => $lg,
    );    
    $manager->$collection->insert($document);

    //shows contect of testData when not empty
    $filter = [];
    $options = [];
    $query = new MongoDB\Driver\Query($filter, $options);
    $cursor = $manager->executeQuery("$user.testData", $query);
    print("The contents of the collection $user.testData are:");
    print_r($cursor->toArray());
?>
  </body>
</html>

A:

Fixed.
Got it to work with:
try {
      $collection->insertOne($document);
   } 
catch (\Exception $e) {
      print("Insert failed.");
      print_r($document);
      print_r($e);
      exit();
    }

I did this.

