I want to insert a json array into my MongoDB, this sounds like a simple task. I am using MongoDB 3.2, PHP 5.5 and XamppServer 32 bit. I have already installed the PHP driver for MongoDB and Composer. So I tried to run the code below:
require "vendor/autoload.php";
$m = new MongoDB\Client();
$db = $m->test;
$collection = $db->foo;
$document = array( "title" => "Mongo Sample", "number" => 2 );
$collection->insert($document);
But at startup, I got this error:
**Fatal error:** Call to undefined method MongoDB\Collection::insert() in C:\xampp\...\test.php on line 13
I cannot figure out how to fix this problem.
source
share