Skip to content

Commit 6c6dd00

Browse files
committed
Updating readme for the query builder
1 parent 3cb81e0 commit 6c6dd00

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

README.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Laravel Eloquent MongoDB [![Build Status](https://travis-ci.org/jenssegers/Laravel-MongoDB.png?branch=master)](https://travis-ci.org/jenssegers/Laravel-MongoDB)
22
========================
33

4-
An Eloquent model that supports MongoDB, inspired by LMongo but using original Eloquent methods.
4+
An Eloquent model that supports MongoDB, inspired by LMongo, but using the original Eloquent methods.
55

6-
*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!*
6+
*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!*
77

88
For more information about Eloquent, check http://laravel.com/docs/eloquent.
99

@@ -24,41 +24,55 @@ Add the service provider in `app/config/app.php`:
2424

2525
'Jenssegers\Mongodb\MongodbServiceProvider',
2626

27-
Usage
28-
-----
27+
Add an alias for the query builder, you can change this alias to your own preference:
2928

30-
Tell your model to use the MongoDB model and a MongoDB collection (alias for table):
31-
32-
use Jenssegers\Mongodb\Model as Eloquent
33-
34-
class MyModel extends Eloquent {
35-
36-
protected $collection = 'mycollection';
37-
38-
}
29+
'MDB' => 'Jenssegers\Mongodb\Facades\DB',
3930

4031
Configuration
4132
-------------
4233

43-
The model will automatically check the database configuration array in `app/config/database.php` for a 'mongodb' item.
34+
This package will automatically check the database configuration in `app/config/database.php` for a 'mongodb' item.
4435

4536
'mongodb' => array(
4637
'host' => 'localhost',
4738
'port' => 27017,
4839
'database' => 'database',
4940
),
5041

51-
You can also specify the connection name in the model:
42+
You can also specify the connection name in the model if you have multiple connections:
5243

5344
class MyModel extends Eloquent {
5445

5546
protected $connection = 'mongodb2';
5647

5748
}
5849

59-
Examples
50+
Eloquent
6051
--------
6152

53+
Tell your model to use the MongoDB model and set the collection (alias for table) property:
54+
55+
use Jenssegers\Mongodb\Model as Eloquent
56+
57+
class MyModel extends Eloquent {
58+
59+
protected $collection = 'mycollection';
60+
61+
}
62+
63+
**Everything else works just like the original Eloquent model.**
64+
65+
Query Builder
66+
-------------
67+
68+
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):
69+
70+
$users = MDB::collection('users')->get();
71+
$user = MDB::collection('users')->where('name', 'John')->first();
72+
73+
More examples
74+
-------------
75+
6276
**Retrieving All Models**
6377

6478
$users = User::all();

0 commit comments

Comments
 (0)