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
+12-179
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,18 @@ This installs the module from npm and adds it as a dependency to the application
14
14
15
15
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.
16
16
17
+
## Supported versions
18
+
19
+
**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.**
20
+
21
+
This module adopts the [Module Long Term Support (LTS)](http://github.com/CloudNativeJS/ModuleLTS) policy, with the following End Of Life (EOL) dates:
22
+
23
+
| 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.
39
-
The generator will prompt for the database server hostname, port, and other settings
40
-
required to connect to a MongoDB database. It will also run the `npm install` command above for you.
41
-
42
-
The entry in the application's `/server/datasources.json` will look like this:
43
-
44
-
```javascript
45
-
"mydb": {
46
-
"host":"myserver",
47
-
"port":27017,
48
-
"url":"",
49
-
"database":"test",
50
-
"password":"mypassword",
51
-
"name":"mydb",
52
-
"user":"me",
53
-
"authSource":"admin",
54
-
"connector":"mongodb"
55
-
}
56
-
```
57
-
58
-
Edit `datasources.json` to add any other additional properties that you require.
59
-
60
-
</details>
61
-
62
48
If your username or password contains special characters like `@`, `$` etc, encode the whole
63
49
username or password using [encodeURIComponent](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent).
64
50
@@ -131,30 +117,6 @@ If you run a MongoDB with authentification ([Docker's example here](https://gith
131
117
132
118
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).
137
-
If you set `url` to `undefined` or remove the `url` property altogether, the override will not work.
138
-
139
-
For example, for production, use `datasources.production.json` as follows (for example) to overide the `url` setting in `datasources.json:
140
-
141
-
```javascript
142
-
"mydb": {
143
-
"host":"myserver",
144
-
"port":27017,
145
-
"url":false,
146
-
"database":"test",
147
-
"password":"mypassword",
148
-
"name":"mydb",
149
-
"user":"me",
150
-
"connector":"mongodb"
151
-
}
152
-
```
153
-
154
-
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).
155
-
156
-
</details>
157
-
158
120
### Using the mongodb+srv protocol
159
121
160
122
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
214
-
215
-
By default, examples and tests from this module assume there is a MongoDB server
216
-
instance running on localhost at port 27017.
217
-
218
-
To customize the settings, you can drop in a `.loopbackrc` file to the root directory
219
-
of the project or the home folder.
220
-
221
-
**Note**: Tests and examples in this project configure the data source using the deprecated '.loopbackrc' file method,
222
-
which is not supported in general.
223
-
For information on configuring the connector in a LoopBack application, please refer to [loopback.io](http://loopback.io/doc/en/lb2/MongoDB-connector.html).
224
-
225
-
The .loopbackrc file is in JSON format, for example:
226
-
227
-
{
228
-
"dev": {
229
-
"mongodb": {
230
-
"host": "127.0.0.1",
231
-
"database": "test",
232
-
"user": "youruser",
233
-
"password": "yourpass",
234
-
"port": 27017
235
-
}
236
-
},
237
-
"test": {
238
-
"mongodb": {
239
-
"host": "127.0.0.1",
240
-
"database": "test",
241
-
"user": "youruser",
242
-
"password": "yourpass",
243
-
"port": 27017
244
-
}
245
-
}
246
-
}
247
-
248
-
**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.
249
-
250
-
</details>
251
-
252
160
## Update Operators
253
161
254
162
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.
@@ -259,19 +167,6 @@ Here is an example of updating the price for all the products under category `fu
259
167
await productRepo.updateAll({ $max: { price: 100 }}, { category: {eq: 'furniture'} // where clause goes in here });
"collection": "Custom_Collection_User", //custom name
438
-
},
439
-
},
440
-
"properties": {
441
-
{
442
-
"id": {
443
-
"type": "String",
444
-
"id": true,
445
-
"required":true,
446
-
},
447
-
"name": {
448
-
"type": "String",
449
-
"mongodb": {"fieldName": "Custom_Name"},}, //custom name
450
-
}
451
-
},
452
-
}
453
-
```
454
-
455
-
</details>
456
-
457
290
{% 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