1. Go to this page and download the library: Download agentejo/mongo-lite library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
agentejo / mongo-lite example snippets
php
$client = new MongoLite\Client(PATH_TO_WRITABLE_FOLDER);
$database = $client->testdb;
$collection = $database->products;
$entry = ["name"=>"Super cool Product", "price"=>20];
$collection->insert($entry);
$products = $collection->find(); // Get Cursor
if ($products->count()) {
foreach($products->sort(["price"=>1])->limit(5) as $product) {
var_dump($product);
}
}
php
$collection->find(function($document) { // recommended to query data
return $document["price"] > 10;
});
//or
$collection->find(["price"=>['$gt'=>10]]); // only very simple criteria is supported (can be slow)
//or just one
$collection->findOne(function($document) { ... });
$collection->findOne([...]);