You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
5
5
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!*
7
7
8
8
For more information about Eloquent, check http://laravel.com/docs/eloquent.
9
9
@@ -24,41 +24,55 @@ Add the service provider in `app/config/app.php`:
24
24
25
25
'Jenssegers\Mongodb\MongodbServiceProvider',
26
26
27
-
Usage
28
-
-----
27
+
Add an alias for the query builder, you can change this alias to your own preference:
29
28
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',
39
30
40
31
Configuration
41
32
-------------
42
33
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.
44
35
45
36
'mongodb' => array(
46
37
'host' => 'localhost',
47
38
'port' => 27017,
48
39
'database' => 'database',
49
40
),
50
41
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:
52
43
53
44
class MyModel extends Eloquent {
54
45
55
46
protected $connection = 'mongodb2';
56
47
57
48
}
58
49
59
-
Examples
50
+
Eloquent
60
51
--------
61
52
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):
0 commit comments