Skip to content

Instantly share code, notes, and snippets.

@bjpeterdelacruz
Created November 23, 2016 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjpeterdelacruz/0875be7e2ff8f4b1d4b9de23bfcf0ef5 to your computer and use it in GitHub Desktop.
Save bjpeterdelacruz/0875be7e2ff8f4b1d4b9de23bfcf0ef5 to your computer and use it in GitHub Desktop.
Updating a document in a MongoDB database (PHP 5 vs. PHP 7)
// PHP 5
$m = new MongoClient();
$db = $m->test;
$collection = $db->todos;
$collection->update(
array("_id" => new MongoId($id)),
array('$set' =>
array("title" => "MongoDB Tutorial")
)
);
// PHP 7
$m = new MongoDB\Driver\Manager();
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->update(
array("_id" => new MongoDB\BSON\ObjectId($id)),
array("title" => "MongoDB Tutorial")
);
$m->executeBulkWrite('test.todos', $bulk);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment