Skip to content

Instantly share code, notes, and snippets.

@thomaslorentsen
Created September 12, 2016 23:44
Show Gist options
  • Save thomaslorentsen/1a52eae14721b94ae97d47b665448307 to your computer and use it in GitHub Desktop.
Save thomaslorentsen/1a52eae14721b94ae97d47b665448307 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
$manager = new MongoDB\Driver\Manager("mongodb://192.168.33.96:27017");
$collection = new MongoDB\Collection($manager, "phplib_demo.write", 'test');
$result = $collection->insertOne(array(
'firstname' => 'hello',
'lastname' => 'world',
));
$result = $collection->insertOne(array(
'firstname' => 'onetwothreefour',
'lastname' => 'bbb',
));
printf("Inserted _id: %s\n\n", $result->getInsertedId());
$cursor = $collection->find(
["firstname" => new \MongoDB\BSON\Regex('four', 'is')],
['comment' => 'test query']
);
foreach($cursor as $document) {
var_dump($document);
}
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment