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
@@ -19,6 +19,18 @@ This installs the module from npm and adds it as a dependency to the application
19
19
20
20
If you create a MongoDB data source using the data source generator as described below, you don't have to do this, since the generator will run `npm install` for you.
21
21
22
+
## Supported versions
23
+
24
+
**Starting from the version 6.0.0, this connector is no longer compatible with LoopBack 3. Please use the latest 5.x version in your LoopBack 3 applications.**
25
+
26
+
This module adopts the [Module Long Term Support (LTS)](http://github.com/CloudNativeJS/ModuleLTS) policy, with the following End Of Life (EOL) dates:
27
+
28
+
| Version | Status | Published | EOL | LoopBack | Juggler |
For LoopBack 4 users, use the LB4 [Command-line interface](https://loopback.io/doc/en/lb4/Command-line-interface.html) to generate a DataSource with MongoDB connector to your LB4 application. Run [`lb4 datasource`](https://loopback.io/doc/en/lb4/DataSource-generator.html), it will prompt for configurations such as host, post, etc. that are required to connect to a MongoDB database.
Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a MongoDB data source to your application.
44
-
The generator will prompt for the database server hostname, port, and other settings
45
-
required to connect to a MongoDB database. It will also run the `npm install` command above for you.
46
-
47
-
The entry in the application's `/server/datasources.json` will look like this:
48
-
49
-
```javascript
50
-
"mydb": {
51
-
"host":"myserver",
52
-
"port":27017,
53
-
"url":"",
54
-
"database":"test",
55
-
"password":"mypassword",
56
-
"name":"mydb",
57
-
"user":"me",
58
-
"authSource":"admin",
59
-
"connector":"mongodb"
60
-
}
61
-
```
62
-
63
-
Edit `datasources.json` to add any other additional properties that you require.
64
-
65
-
</details>
66
-
67
53
If your username or password contains special characters like `@`, `$` etc, encode the whole
68
54
username or password using [encodeURIComponent](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent).
69
55
@@ -136,30 +122,6 @@ If you run a MongoDB with authentification ([Docker's example here](https://gith
136
122
137
123
You can set the `url` property to a connection URL in `<datasourceName>.datasources.ts` to override individual connection parameters such as `host`, `user`, and `password`. E.g `loopback:pa55w0rd@localhost:27017/testdb`.
For LB3 users, you can override the global `url` property in environment-specific data source configuration files, for example for production in `datasources.production.json`, and use the individual connection parameters `host`, `user`, `password`, and `port`. To do this, you _must_ set `url` to `false`, null, or “” (empty string).
142
-
If you set `url` to `undefined` or remove the `url` property altogether, the override will not work.
143
-
144
-
For example, for production, use `datasources.production.json` as follows (for example) to overide the `url` setting in `datasources.json:
145
-
146
-
```javascript
147
-
"mydb": {
148
-
"host":"myserver",
149
-
"port":27017,
150
-
"url":false,
151
-
"database":"test",
152
-
"password":"mypassword",
153
-
"name":"mydb",
154
-
"user":"me",
155
-
"connector":"mongodb"
156
-
}
157
-
```
158
-
159
-
For more information on setting data source configurations for different environments, see [Environment-specific configuration](https://loopback.io/doc/en/lb3/Environment-specific-configuration.html#data-source-configuration).
160
-
161
-
</details>
162
-
163
125
### Using the mongodb+srv protocol
164
126
165
127
MongoDB supports a protocol called `mongodb+srv` for connecting to replica sets without having to give the hostname of every server in the replica set.
## Customizing MongoDB configuration for tests/examples
219
-
220
-
By default, examples and tests from this module assume there is a MongoDB server
221
-
instance running on localhost at port 27017.
222
-
223
-
To customize the settings, you can drop in a `.loopbackrc` file to the root directory
224
-
of the project or the home folder.
225
-
226
-
**Note**: Tests and examples in this project configure the data source using the deprecated '.loopbackrc' file method,
227
-
which is not supported in general.
228
-
For information on configuring the connector in a LoopBack application, please refer to [loopback.io](http://loopback.io/doc/en/lb2/MongoDB-connector.html).
229
-
230
-
The .loopbackrc file is in JSON format, for example:
231
-
232
-
{
233
-
"dev": {
234
-
"mongodb": {
235
-
"host": "127.0.0.1",
236
-
"database": "test",
237
-
"user": "youruser",
238
-
"password": "yourpass",
239
-
"port": 27017
240
-
}
241
-
},
242
-
"test": {
243
-
"mongodb": {
244
-
"host": "127.0.0.1",
245
-
"database": "test",
246
-
"user": "youruser",
247
-
"password": "yourpass",
248
-
"port": 27017
249
-
}
250
-
}
251
-
}
252
-
253
-
**Note**: user/password is only required if the MongoDB server has authentication enabled. `"authSource"` should be used if you cannot log in to your database using your credentials.
254
-
255
-
</details>
256
-
257
165
## Update Operators
258
166
259
167
Except the comparison and logical operators LoopBack supports in the [operator list](https://loopback.io/doc/en/lb4/Where-filter.html#operators) of `Where` filter, you can also enable [MongoDB update operators](https://docs.mongodb.com/manual/reference/operator/update/) for `update*` methods by setting the flag `allowExtendedOperators` to `true` in the datasource configuration.
@@ -264,19 +172,6 @@ Here is an example of updating the price for all the products under category `fu
264
172
await productRepo.updateAll({ $max: { price: 100 }}, { category: {eq: 'furniture'} // where clause goes in here });
"collection": "Custom_Collection_User", //custom name
443
-
},
444
-
},
445
-
"properties": {
446
-
{
447
-
"id": {
448
-
"type": "String",
449
-
"id": true,
450
-
"required":true,
451
-
},
452
-
"name": {
453
-
"type": "String",
454
-
"mongodb": {"fieldName": "Custom_Name"},}, //custom name
455
-
}
456
-
},
457
-
}
458
-
```
459
-
460
-
</details>
461
-
462
295
{% include important.html content="Since in MongoDB `_id` is reserved for the primary key, LoopBack **does not** allow customization of the field name for the id property. Please use `id` as is. Customizing the id property would cause errors." %}
0 commit comments