dev-master
9999999-devMinimal Mongo Client for Laravel
The Requires
- php >=5.3.0
- illuminate/database 4.2.*
- illuminate/support 4.2.*
by Mohit Mamoria
Wallogit.com
2017 © Pedro Peláez
Minimal Mongo Client for Laravel
Minimal MongoDb for Laravel apps., (*1)
This package provides simple to use MongoDB structure and authentication, to get you started with MongoDB in Laravel in less than 10 seconds., (*2)
You can install this package by requiring it in your composer.json., (*3)
"owlgrin/mongo": "dev-master"
The add the following service provider in your app.php configuration file., (*4)
'Owlgrin\Mongo\MongoServiceProvider'
Lastly, you will have to list out your MongoDb connection credentials in your database.php configuration file. Add the connections like so:, (*5)
...
'connections' => array(
...
'mongo' => array(
'driver' => 'mongo',
'host' => 'localhost',
'port' => 27017,
'username' => 'username',
'password' => 'password',
'database' => 'dbname'
)
)
To leverage the benefits of replica sets, you can describe the configuration like this:, (*6)
...
'connections' => array(
...
'mongo' => array(
'driver' => 'mongo',
'host' => array('server1', 'server2'),
'port' => 27017,
'username' => 'username',
'password' => 'password',
'database' => 'experiment',
'options' => array('replicaSet' => 'someReplicaSet')
)
)
With this package, you can use MongoDb like this:, (*7)
$user = DB::connection('mongo')
->users
->find(array('is_active' => 1));
If you are using MongoDb exclusively, you can set the default property in database.php configuration file to mongo, to make the usage easier, like so:, (*8)
$users = DB::collection('users')->find(array('is_active' => 1));
This package comes bundled with the authentication driver for MongoDB. To set it up, do these steps., (*9)
app/config/auth.php to 'mongo';'driver' => 'mongo'
app/config/auth.php file./* |-------------------------------------------------------------------------- | Authentication Collection |-------------------------------------------------------------------------- | | When using the "Mongo" authentication driver, we need to know which | collection should be used to retrieve your users. We have chosen a basic | default value but you may easily change it to any table you like. | */ 'collection' => 'users', /* |-------------------------------------------------------------------------- | Hashed or Encrypted Password |-------------------------------------------------------------------------- | | In some cases, you may need to store passwords encrypted as opposed to | hashed generally. For instance, API secret keys for your users can be stored | encrypted and not hashed, as they are to be decrypted and shown to | users in their accounts (and storing them in plain text is a very bad idea). | By default, we assume that the password will be hashed. If it is encrypted, | set the following option to true. | */ 'encrypted_password' => false,
That's it! Now, you can authenticate your users using MongoDB. No other change is required in your whole code - it just works!, (*10)
We are not sure, if we will extend the functionalities of this package. We wanted something to get started quickly. If you want something more extensive, Jens has a great package for you: https://github.com/jenssegers/Laravel-MongoDB., (*11)
Minimal Mongo Client for Laravel