Server-Side Scripting/Document Databases/PHP

index.php
";   return $result; }

function country_exists($country) { $manager = new MongoDB\Driver\Manager($GLOBALS["HOST"]); $query = [ "country" => $country ];   $count = [ "count" => $GLOBALS["COLLECTION"], "query" => $query ];   $command = new MongoDB\Driver\Command($count); $cursor = $manager->executeReadCommand(       $GLOBALS["DATABASE"],        $command); $result = current($cursor->toArray)->n; return !!$result; }

function insert_country($country, $temperature) { $manager = new MongoDB\Driver\Manager($GLOBALS["HOST"]); $bulk = new MongoDB\Driver\BulkWrite; $document = [ "country" => $country, "temperature" => $temperature ];   $bulk->insert($document); $manager->executeBulkWrite(       $GLOBALS["DATABASE"] . "." . $GLOBALS["COLLECTION"],         $bulk); }

function update_country($country, $temperature) { $manager = new MongoDB\Driver\Manager($GLOBALS["HOST"]); $bulk = new MongoDB\Driver\BulkWrite; $filter = [ "country" => $country ];   $update = [ '$set' => [ "temperature" => $temperature ] ];   $bulk->update($filter, $update); $manager->executeBulkWrite(       $GLOBALS["DATABASE"] . "." . $GLOBALS["COLLECTION"],         $bulk); }

function delete_country($country) { $manager = new MongoDB\Driver\Manager($GLOBALS["HOST"]); $bulk = new MongoDB\Driver\BulkWrite; $filter = [ "country" => $country ];   $bulk->delete($filter); $manager->executeBulkWrite(       $GLOBALS["DATABASE"] . "." . $GLOBALS["COLLECTION"],         $bulk); }

?>

Try It

 * 1) Use Docker/MongoDB to run a MongoDB server.
 * 2) Use Docker/PHP and copy and paste the code above to run as the PHP application. Be sure to modify the MongoDB host address to match the address received by your MongoDB server.