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
Copy file name to clipboardExpand all lines: README.md
+15-26Lines changed: 15 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -143,47 +143,36 @@ Keep in mind that these traits are not yet supported:
143
143
144
144
Configuration
145
145
-------------
146
-
You can use MongoDB either as the main database, either as a side database. To do so, add a new `mongodb` connection to `config/database.php`:
146
+
147
+
To configure a new MongoDB connection, add a new connection entry to `config/database.php`:
147
148
148
149
```php
149
150
'mongodb' => [
150
151
'driver' => 'mongodb',
151
-
'host' => env('DB_HOST', '127.0.0.1'),
152
-
'port' => env('DB_PORT', 27017),
152
+
'dsn' => env('DB_DSN'),
153
153
'database' => env('DB_DATABASE', 'homestead'),
154
-
'username' => env('DB_USERNAME', 'homestead'),
155
-
'password' => env('DB_PASSWORD', 'secret'),
156
-
'options' => [
157
-
// here you can pass more settings to the Mongo Driver Manager
158
-
// see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use
159
-
160
-
'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'), // required with Mongo 3+
161
-
],
162
154
],
163
155
```
164
156
165
-
For multiple servers or replica set configurations, set the host to an array and specify each server host:
157
+
The `dsn` key contains the connection string used to connect to your MongoDB deployment. The format and available options are documented in the [MongoDB documentation](https://docs.mongodb.com/manual/reference/connection-string/).
158
+
159
+
Instead of using a connection string, you can also use the `host` and `port` configuration options to have the connection string created for you.
166
160
167
161
```php
168
162
'mongodb' => [
169
163
'driver' => 'mongodb',
170
-
'host' => ['server1', 'server2', ...],
171
-
...
164
+
'host' => env('DB_HOST', '127.0.0.1'),
165
+
'port' => env('DB_PORT', 27017),
166
+
'database' => env('DB_DATABASE', 'homestead'),
167
+
'username' => env('DB_USERNAME', 'homestead'),
168
+
'password' => env('DB_PASSWORD', 'secret'),
172
169
'options' => [
173
-
'replicaSet' => 'rs0',
170
+
'appname' => 'homestead',
174
171
],
175
172
],
176
173
```
177
174
178
-
If you wish to use a connection string instead of full key-value params, you can set it so. Check the documentation on MongoDB's URI format: https://docs.mongodb.com/manual/reference/connection-string/
179
-
180
-
```php
181
-
'mongodb' => [
182
-
'driver' => 'mongodb',
183
-
'dsn' => env('DB_DSN'),
184
-
'database' => env('DB_DATABASE', 'homestead'),
185
-
],
186
-
```
175
+
The `options` key in the connection configuration corresponds to the [`uriOptions` parameter](https://www.php.net/manual/en/mongodb-driver-manager.construct.php#mongodb-driver-manager.construct-urioptions).
187
176
188
177
Eloquent
189
178
--------
@@ -223,7 +212,7 @@ class Book extends Model
223
212
protected $primaryKey = 'id';
224
213
}
225
214
226
-
// Mongo will also create _id, but the 'id' property will be used for primary key actions like find().
215
+
// MongoDB will also create _id, but the 'id' property will be used for primary key actions like find().
227
216
Book::create(['id' => 1, 'title' => 'The Fault in Our Stars']);
228
217
```
229
218
@@ -238,7 +227,7 @@ class Book extends Model
238
227
}
239
228
```
240
229
241
-
### Extending the Authenticable base model
230
+
### Extending the Authenticatable base model
242
231
This package includes a MongoDB Authenticatable Eloquent class `Jenssegers\Mongodb\Auth\User` that you can use to replace the default Authenticatable class `Illuminate\Foundation\Auth\User` for your `User` model.
0 commit comments