lalbert / silex-mongodb
Simple mongodb service provider for Silex 2.x and official mongodb driver
Installs: 2 032
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- mongodb/mongodb: ~1.0
- silex/api: ~2.0
Requires (Dev)
- codacy/coverage: dev-master
- phpunit/phpunit: ~4.8 || ~5.3
- silex/silex: ~2.0
This package is auto-updated.
Last update: 2024-12-24 21:00:59 UTC
README
Simple mongodb service provider for Silex 2.x and official mongodb driver
Features
This library provides easy access to a MongoDB database using the extension (mongodb, not mongo) and the official MongoDB PHP driver.
Requirements
- PHP 5.4+
- mongodb official PECL extension
Installation
The best way to install the component is using Composer
$ composer require lalbert/silex-mongodb
Usage
Register service
$app->register(new MongoDBServiceProvider());
You can also pass configuration settings :
See http://php.net/manual/en/mongodb-driver-manager.construct.php for options allowed.
$app->register(new MongoDBServiceProvider(), [
'mongodb.config' => [
'server' => 'mongodb://localhost:27017',
'options' => [],
'driverOptions' => [],
]
]);
Your application :
$document = ['key' => 'value'];
$app['mongodb']
->mydatabase
->mycollection
->insert($document)
;
See official MongoDB PHP Library documentation