Professional Documents
Culture Documents
Abhishekphp
Abhishekphp
Practical #9
Name Abhishek Mishra Roll Number 20302C0037
Subject/Course: NGT
Topic PHP and MongoDB
1. Inserting :-
Code:-
<?php
//connect to mongodb
$m=new MongoDB\Driver\Manager("mongodb://localhost:27017");
echo "Connection to database successfully";
$bulk = new MongoDB\Driver\BulkWrite;
$document1 = ['title' => 'one'];
$document2 = ['_id' => 'custom ID', 'title' => 'two'];
$document3 = ['_id' => new MongoDB\BSON\ObjectId, 'title' => 'three'];
$_id1 = $bulk->insert($document1);
$_id2 = $bulk->insert($document2);
$_id3 = $bulk->insert($document3);
var_dump($_id1, $_id2, $_id3);
$result = $m->executeBulkWrite('mydd5.data', $bulk);
echo "Document inserted successfully";
?>
Output Screenshot:-
Output Screenshot:-
Output Screenshot:-