1. Go to this page and download the library: Download maer/mongo-query 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/ */
maer / mongo-query example snippets
// Load composers autoloader
ents and a MongoDB\Client instance will be created
// (using localhost and default port)
$client = new Maer\MongoQuery\Connection();
// To use a custom client instance, pass it as the first argument
$client = $client = new Maer\MongoQuery\Connection(
new MongoDB\Client('mongodb://example.com:1234')
);
// Get a database
$db = $client->myDatabase; // Or: $client->getDatabase('myDatabase');
// Get a collection
$collection = $db->myCollection; // Or: $db->getCollection('myCollection');
// Add some criterias
$result = $collection->where('some-key', 'some-value')
->orderBy('some-key', 'asc')
->get();
// $result will now contain an array with the matched documents
$id = $collection->insert([
'some-key' => 'some-value',
]);
// $id contains the new id for the inserted document or false on error
$ids = $collection->insert([
[
'some-key' => 'some-value',
],
[
'some-key' => 'some-other-value',
]
]);
// $ids contains an array of the new ids for the inserted documents or false on error
$result = $collection->get();
$result = $collection->first();
// Find by _id (default)
$result = $collection->find('123');
// Find by some other key (is equal to)
$result = $collection->find('some-value', 'some-key');
$result = $collection->where('some-key', 'some-value')->count();
// $result is an integer with the number of matched documents