Home:ALL Converter>Record not inserting into MongoDB using PHP

Record not inserting into MongoDB using PHP

Ask Time:2020-04-13T18:33:52         Author:SUMAN KHAMARU

Json Formatter

I have created mongodb database 'employee' and collection 'personal' into the database. Now I'm trying to connect the db using php, it's connecting but when I'm trying to insert data into the collections, nothing is happened, here is my script :

<?php
   // connect to mongodb
    error_reporting(0);
   $m = new MongoDB\Driver\Manager("mongodb://localhost:27017");

   echo "Connection to database successfully"."<br>";
   // select a database
   $db = $m->employee;

   echo "Database selected"."<br>";

   $collection = $db->personal;

   echo "Collection selected"."<br>";

   $collection->insertOne(["name"=>"Rajib", "address"=>"Delhi", "contact"=>123, "gender"=>"Male", "dept"=>"PHP"]);


   echo "Document inserted successfully";
?>

What's wrong here?

Author:SUMAN KHAMARU,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/61185995/record-not-inserting-into-mongodb-using-php
yy