coderockr / silex-mongodb-provider
Silex Service Provider to access Mongodb
Installs: 2 150
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 4
Forks: 7
Open Issues: 1
Requires
- php: >=5.4
- mongodb/mongodb: ^1.0.0@beta
- silex/silex: ~1.3
Requires (Dev)
- phpunit/phpunit: ^5.1
This package is not auto-updated.
Last update: 2024-12-21 20:08:36 UTC
README
Install
php composer.phar require coderockr/silex-mongodb-provider
Usage
<?php
require_once __DIR__.'/vendor/autoload.php';
use Silex\Application;
use Coderockr\Mongodb\ServiceProvider as MongodbServiceProvider;
$app = new Application();
$app->register(new MongodbServiceProvider(), [
'mongodb.options' => [
'uri' => 'mongodb://localhost:27017'
]
]);
$manager = $app['mongodb']; // or $app['mongodbs']['default'];
$collection = new MongoDB\Collection($manager, "demo.beers");
$result = $collection->insertOne(['name' => 'Hinterland', 'brewery' => 'BrewDog']);
echo "Inserted with Object ID '{$result->getInsertedId()}'";