-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectMongo.php
More file actions
25 lines (19 loc) · 784 Bytes
/
ConnectMongo.php
File metadata and controls
25 lines (19 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
# filename ConnectMongo.php
require_once __DIR__ . "/vendor/autoload.php";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// connect to mongodb
//$manager = new MongoDB\Driver\Manager('mongodb://username:password@127.0.0.1'); //required username+pass
//$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017', ["username" => "joe", "password" => "test"]); // optional username+pass
$manager = new MongoClient('mongodb://localhost:27017');
$id = new \MongoDB\BSON\ObjectId("5a0c8e2362eb6404c2f10032");
$filter = ['_id' => $id];
$options = [];
$query = new \MongoDB\Driver\Query($filter, $options);
$rows = $manager->executeQuery('db.collection', $query);
foreach ($rows as $document) {
var_dump($document);
}
?>