An Eloquent model that supports MongoDB, inspired by LMongo but using original Eloquent methods.
An Eloquent model that supports MongoDB, inspired by LMongo, but using the original Eloquent methods.
*This model extends the original Eloquent model so it uses exactly the same methods. Please note that some advanced Eloquent features may not be working, but feel free to issue a pull request!*
*This model extends the original Eloquent model, so it uses exactly the same methods. Some advanced Eloquent features may not be working, but feel free to report them or issue a pull request!*
For more information about Eloquent, check http://laravel.com/docs/eloquent.
For more information about Eloquent, check http://laravel.com/docs/eloquent.
...
@@ -24,23 +24,14 @@ Add the service provider in `app/config/app.php`:
...
@@ -24,23 +24,14 @@ Add the service provider in `app/config/app.php`:
'Jenssegers\Mongodb\MongodbServiceProvider',
'Jenssegers\Mongodb\MongodbServiceProvider',
Usage
Add an alias for the query builder, you can change this alias to your own preference:
-----
Tell your model to use the MongoDB model and a MongoDB collection (alias for table):
'MDB' => 'Jenssegers\Mongodb\Facades\DB',
use Jenssegers\Mongodb\Model as Eloquent
class MyModel extends Eloquent {
protected $collection = 'mycollection';
}
Configuration
Configuration
-------------
-------------
The model will automatically check the database configuration array in `app/config/database.php` for a 'mongodb' item.
This package will automatically check the database configuration in `app/config/database.php` for a 'mongodb' item.
'mongodb' => array(
'mongodb' => array(
'host' => 'localhost',
'host' => 'localhost',
...
@@ -48,7 +39,7 @@ The model will automatically check the database configuration array in `app/conf
...
@@ -48,7 +39,7 @@ The model will automatically check the database configuration array in `app/conf
'database' => 'database',
'database' => 'database',
),
),
You can also specify the connection name in the model:
You can also specify the connection name in the model if you have multiple connections:
class MyModel extends Eloquent {
class MyModel extends Eloquent {
...
@@ -56,9 +47,32 @@ You can also specify the connection name in the model:
...
@@ -56,9 +47,32 @@ You can also specify the connection name in the model:
}
}
Examples
Eloquent
--------
--------
Tell your model to use the MongoDB model and set the collection (alias for table) property:
use Jenssegers\Mongodb\Model as Eloquent
class MyModel extends Eloquent {
protected $collection = 'mycollection';
}
**Everything else works just like the original Eloquent model.**
Query Builder
-------------
The MongoDB query builder allows you to execute queries, just like the original query builder (note that we are using the previously created alias here):