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
For usage with [Lumen](http://lumen.laravel.com), add the service provider in `bootstrap/app.php`. In this file, you will also need to enable Eloquent. You must however ensure that your call to `$app->withEloquent();` is **below** where you have registered the `MongodbServiceProvider`:
@@ -104,19 +100,10 @@ Embedded relations now return an `Illuminate\Database\Eloquent\Collection` rathe
104
100
$books = $user->books()->sortBy('title');
105
101
```
106
102
107
-
Testing
108
-
-------
109
-
110
-
To run the test for this package, run:
111
-
112
-
```
113
-
docker-compose up
114
-
```
115
-
116
103
Configuration
117
104
-------------
118
105
119
-
Change your default database connection name in `config/database.php`:
106
+
Change your default database connection name in `app/config/database.php`:
120
107
121
108
```php
122
109
'default' => env('DB_CONNECTION', 'mongodb'),
@@ -129,11 +116,11 @@ And add a new mongodb connection:
129
116
'driver' => 'mongodb',
130
117
'host' => env('DB_HOST', 'localhost'),
131
118
'port' => env('DB_PORT', 27017),
132
-
'database' => env('DB_DATABASE'),
133
-
'username' => env('DB_USERNAME'),
134
-
'password' => env('DB_PASSWORD'),
135
-
'options' => [
136
-
'database' => 'admin' // sets the authentication database required by mongo 3
119
+
'database' => env('DB_DATABASE', ''),
120
+
'username' => env('DB_USERNAME', ''),
121
+
'password' => env('DB_PASSWORD', ''),
122
+
'options' => [
123
+
'db' => 'admin' // sets the authentication database required by mongo 3
137
124
]
138
125
],
139
126
```
@@ -145,27 +132,13 @@ You can connect to multiple servers or replica sets with the following configura
145
132
'driver' => 'mongodb',
146
133
'host' => ['server1', 'server2'],
147
134
'port' => env('DB_PORT', 27017),
148
-
'database' => env('DB_DATABASE'),
149
-
'username' => env('DB_USERNAME'),
150
-
'password' => env('DB_PASSWORD'),
151
-
'options' => [
152
-
'replicaSet' => 'replicaSetName'
153
-
]
135
+
'database' => env('DB_DATABASE', ''),
136
+
'username' => env('DB_USERNAME', ''),
137
+
'password' => env('DB_PASSWORD', ''),
138
+
'options' => ['replicaSet' => 'replicaSetName']
154
139
],
155
140
```
156
141
157
-
Alternatively, you can use MongoDB connection string:
158
-
159
-
```php
160
-
'mongodb' => [
161
-
'driver' => 'mongodb',
162
-
'dsn' => env('DB_DSN'),
163
-
'database' => env('DB_DATABASE'),
164
-
],
165
-
```
166
-
167
-
Please refer to MongoDB official docs for its URI format: https://docs.mongodb.com/manual/reference/connection-string/
168
-
169
142
Eloquent
170
143
--------
171
144
@@ -177,7 +150,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
177
150
class User extends Eloquent {}
178
151
```
179
152
180
-
Note that we did not tell Eloquent which collection to use for the `User` model. Just like the original Eloquent, the lower-case, plural name of the class will be used as the collection name unless another name is explicitly specified. You may specify a custom collection (alias for table) by defining a `collection` property on your model:
153
+
Note that we did not tell Eloquent which collection to use for the `User` model. Just like the original Eloquent, the lower-case, plural name of the class will be used as the table name unless another name is explicitly specified. You may specify a custom collection (alias for table) by defining a `collection` property on your model:
181
154
182
155
```php
183
156
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
@@ -205,10 +178,10 @@ Everything else (should) work just like the original Eloquent model. Read more a
205
178
206
179
### Optional: Alias
207
180
208
-
You may also register an alias for the MongoDB model by adding the following to the alias array in `config/app.php`:
181
+
You may also register an alias for the MongoDB model by adding the following to the alias array in `app/config/app.php`:
All other (unsupported) operations are implemented as dummy pass-through methods, because MongoDB does not use a predefined schema. Read more about the schema builder on http://laravel.com/docs/schema
263
236
264
-
### Geospatial indexes
265
-
266
-
Geospatial indexes are handy for querying location-based documents. They come in two forms: `2d` and `2dsphere`. Use the schema builder to add these to a collection.
267
-
268
-
To add a `2d` index:
269
-
270
-
```php
271
-
Schema::create('users', function($collection)
272
-
{
273
-
$collection->geospatial('name', '2d');
274
-
});
275
-
```
276
-
277
-
To add a `2dsphere` index:
278
-
279
-
```php
280
-
Schema::create('users', function($collection)
281
-
{
282
-
$collection->geospatial('name', '2dsphere');
283
-
});
284
-
```
285
-
286
237
Extensions
287
238
----------
288
239
@@ -310,21 +261,6 @@ If you want to use MongoDB as your database backend, change the the driver in `c
310
261
],
311
262
```
312
263
313
-
If you want to use MongoDB to handle failed jobs, change the database in `config/queue.php`:
If you want to use this library with [Sentry](https://cartalyst.com/manual/sentry), then check out https://github.com/jenssegers/Laravel-MongoDB-Sentry
@@ -453,15 +389,6 @@ Aggregations can be combined with **where**:
Selects documents where values match a specified regular expression.
540
467
541
468
```php
542
-
User::where('name', 'regex', new \MongoDB\BSON\Regex("/.*doe/i"))->get();
469
+
User::where('name', 'regex', new MongoRegex("/.*doe/i"))->get();
543
470
```
544
471
545
-
**NOTE:** you can also use the Laravel regexp operations. These are a bit more flexible and will automatically convert your regular expression string to a MongoDB\BSON\Regex object.
472
+
**NOTE:** you can also use the Laravel regexp operations. These are a bit more flexible and will automatically convert your regular expression string to a MongoRegex object.
Matches documents that satisfy a JavaScript expression. For more information check http://docs.mongodb.org/manual/reference/operator/query/where/#op._S_where
You can also perform raw expressions on the internal MongoCollection object. If this is executed on the model class, it will return a collection of models. If this is executed on the query builder, it will return the original response.
0 commit comments