Skip to content

Commit 5b0a066

Browse files
author
Yaapa Hage
committed
[SEMVER-MAJOR] Drop support for LoopBack 3.x
Signed-off-by: Yaapa Hage <[email protected]>
1 parent f84e930 commit 5b0a066

File tree

5 files changed

+19
-244
lines changed

5 files changed

+19
-244
lines changed

Diff for: README.md

+12-179
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ This installs the module from npm and adds it as a dependency to the application
1414

1515
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.
1616

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 |
24+
| ---------- | -------------------- | --------- | -------------------- | ---------|----------|
25+
| 6.x | Current | Nov 2020 | Apr 2023 _(minimum)_ | 4 | 4.x |
26+
| 5.x | Active LTS | Jun 2019 | Apr 2023 | 3, 4 | 3.x, 4.x |
27+
| 4.x | Maintenance LTS | Nov 2018 | Apr 2021 | 3, 4 | 3.x, 4.x |
28+
1729
## Creating a MongoDB data source
1830

1931
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.
@@ -33,32 +45,6 @@ const config = {
3345
};
3446
```
3547

36-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
37-
38-
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-
6248
If your username or password contains special characters like `@`, `$` etc, encode the whole
6349
username or password using [encodeURIComponent](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent).
6450

@@ -131,30 +117,6 @@ If you run a MongoDB with authentification ([Docker's example here](https://gith
131117

132118
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`.
133119

134-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
135-
136-
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-
158120
### Using the mongodb+srv protocol
159121

160122
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.
@@ -170,19 +132,6 @@ const config = {
170132
};
171133
```
172134

173-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
174-
175-
```javascript
176-
"mydb": {
177-
"connector": "mongodb",
178-
"host": "myserver",
179-
"database": "test",
180-
"protocol": "mongodb+srv"
181-
}
182-
```
183-
184-
</details>
185-
186135
Note: the port is not specified when using the `mongodb+srv` protocol and will be ignored if given.
187136

188137
## Security Considerations
@@ -208,47 +157,6 @@ See [LoopBack 4 types](http://loopback.io/doc/en/lb4/LoopBack-types.html) (or [L
208157

209158
Type conversion is mainly handled by MongoDB. See ['node-mongodb-native'](http://mongodb.github.io/node-mongodb-native/) for details.
210159

211-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
212-
213-
## 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-
252160
## Update Operators
253161

254162
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
259167
await productRepo.updateAll({ $max: { price: 100 }}, { category: {eq: 'furniture'} // where clause goes in here });
260168
```
261169

262-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
263-
264-
```
265-
Product.updateAll(
266-
{ category: {eq: 'furniture'} // where clause goes in here },
267-
{$max: {price: 100}},
268-
options,
269-
function(err, updateproducts) {
270-
...
271-
```
272-
273-
</details>
274-
275170
{% include tip.html content="you **will not** need the dollar sign `'$'` for operators in the Where
276171
clause." %}
277172

@@ -318,23 +213,6 @@ export class User extends Entity {
318213
}
319214
```
320215

321-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
322-
323-
```js
324-
{
325-
"name": "User",
326-
"base": "PersistedModel",
327-
"idInjection": false,
328-
"options": {
329-
"validateUpsert": true,
330-
"strictObjectIDCoercion": true
331-
},
332-
...
333-
}
334-
```
335-
336-
</details>
337-
338216
### Property scope
339217

340218
This scope would only convert an ObjectId-like string to `ObjectId` with a certain property in the model.
@@ -348,24 +226,6 @@ This scope would only convert an ObjectId-like string to `ObjectId` with a certa
348226
id: string;
349227
```
350228
351-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
352-
353-
```js
354-
"properties": {
355-
{
356-
"id": {
357-
"type": "String",
358-
"id": true,
359-
"required":true,
360-
"mongodb": {"dataType":"ObjectId"}
361-
},
362-
// ..
363-
}
364-
}
365-
```
366-
367-
</details>
368-
369229
Also notice that for RELATIONS, if the primary key/source key has set to enforce ObjectId coercion
370230
(no matter by `strictObjectIDCoercion: true` or `dataType: 'ObjectId'`). The corresponding foreign key will need to have it
371231
set as well to make sure relations work smoothly.
@@ -427,33 +287,6 @@ export class User extends Entity {
427287
}
428288
```
429289
430-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
431-
432-
```js
433-
{
434-
"name": "User",
435-
"options": {
436-
"mongodb": {
437-
"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-
457290
{% 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." %}
458291
459292
## Running tests

Diff for: deps/juggler-v3/package.json

-8
This file was deleted.

Diff for: deps/juggler-v3/test.js

-49
This file was deleted.

Diff for: package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "loopback-connector-mongodb",
3-
"version": "5.5.0",
3+
"version": "6.0.0-dev",
44
"description": "The official MongoDB connector for the LoopBack framework.",
55
"engines": {
66
"node": ">=10"
@@ -11,7 +11,7 @@
1111
"coverage": "nyc report --reporter=text-lcov | coveralls",
1212
"benchmarks": "make benchmarks",
1313
"leak-detection": "make leak-detection",
14-
"test": "nyc mocha test/*.test.js node_modules/juggler-v3/test.js node_modules/juggler-v4/test.js",
14+
"test": "nyc mocha test/*.test.js node_modules/juggler-v4/test.js",
1515
"lint": "eslint .",
1616
"posttest": "npm run lint"
1717
},
@@ -48,9 +48,8 @@
4848
"coveralls": "^3.0.4",
4949
"eslint": "^6.6.0",
5050
"eslint-config-loopback": "^13.0.0",
51-
"juggler-v3": "file:./deps/juggler-v3",
5251
"juggler-v4": "file:./deps/juggler-v4",
53-
"loopback-datasource-juggler": "^3.0.0 || ^4.0.0",
52+
"loopback-datasource-juggler": "^4.0.0",
5453
"mocha": "^6.2.0",
5554
"nyc": "^14.1.1",
5655
"rc": "^1.2.8",

Diff for: test/objectid.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ describe('ObjectID', function() {
137137
title: 'arrayOfObjectID',
138138
});
139139
const found = await Article.find({where: {title: 'arrayOfObjectID'}});
140-
// the type of the returned array is actually string even it's stored as ObjectIds in the db as expected
140+
// the type of the returned array is actually string even though they are stored as ObjectIds in the db
141141
found[0].xidArr.should.containDeep([
142-
new ds.ObjectID(objectIDLikeString),
143-
new ds.ObjectID(objectIDLikeString2),
142+
objectIDLikeString,
143+
objectIDLikeString2,
144144
]);
145-
// check if the array is stored in ObjectId
145+
// check if the array is stored as ObjectId in the db
146146
const raw = await findRawModelDataAsync('ArticleC', found[0].id);
147147
raw.xidArr[0].should.be.an.instanceOf(ds.ObjectID);
148148
raw.xidArr[1].should.be.an.instanceOf(ds.ObjectID);

0 commit comments

Comments
 (0)