note 128262 added to set.mongodb
| From: | Robert at main dot php dot net | Date: | Tue, 28 Feb 2023 08:42:35 +0000 |
| Subject: | note 128262 added to set.mongodb | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220220@lists.php.net to get a copy of this message | ||
Hey guys,
a short example to access a local mongo db server:
<?php
echo "Mongo DB Example<br>";
// run composer requre mongodb/mongdodb in your project folder before
require("vendor/autoload.php");
// start mongod process on your instance first
$client = new MongoDB\Client('mongodb://localhost:27017');
// select a database (will be created automatically if it not exists)
$db = $client->test2;
echo "Database test2 created/selected<br>";
// select a collection (will be created automatically if it not exists)
$coll = $db->selectCollection("mycoll");
echo "Collection mycoll created/selected<br>";
// insert a datatow in the collection
$coll->insertOne(['foo' => 'bar']);
// search for the datarow
echo "Result:<br>";
var_dump($coll->findOne(['foo' => 'bar']));
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 2a02:8108:8400:552c:eac1:b162:a9b1:bed3)
----
Manual Page -- https://php.net/manual/en/set.mongodb.php
Edit -- https://main.php.net/note/edit/128262
Del: integrated -- https://main.php.net/note/delete/128262/integrated
Del: useless -- https://main.php.net/note/delete/128262/useless
Del: bad code -- https://main.php.net/note/delete/128262/bad+code
Del: spam -- https://main.php.net/note/delete/128262/spam
Del: non-english -- https://main.php.net/note/delete/128262/non-english
Del: in docs -- https://main.php.net/note/delete/128262/in+docs
Del: other reasons-- https://main.php.net/note/delete/128262
Reject -- https://main.php.net/note/reject/128262
Search -- https://main.php.net/manage/user-notes.php