Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bjpeterdelacruz
Last active November 13, 2018 06:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjpeterdelacruz/eaa2dc7db0c6f1465ceed658e2f01f31 to your computer and use it in GitHub Desktop.
Save bjpeterdelacruz/eaa2dc7db0c6f1465ceed658e2f01f31 to your computer and use it in GitHub Desktop.
Inserting a document into MongoDB database (PHP 5 vs. PHP 7)
// PHP 5
$m = new MongoClient();
$db = $m->test;
$collection = $db->todos;
$collection->insert(array("name" => $name));
// PHP 7
$m = new MongoDB\Driver\Manager();
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(array("name" => $name));
$m->executeBulkWrite('test.todos', $bulk);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment