Skip to content

Commit 7393fc5

Browse files
author
Hage Yaapa
authored
Merge pull request #602 from strongloop/drop-juggler3-support
[SEMVER-MAJOR] Drop support for LoopBack 3.x
2 parents dacd7f2 + 5b0a066 commit 7393fc5

File tree

5 files changed

+19
-244
lines changed

5 files changed

+19
-244
lines changed

README.md

Lines changed: 12 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ This installs the module from npm and adds it as a dependency to the application
1919

2020
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.
2121

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 |
29+
| ---------- | -------------------- | --------- | -------------------- | ---------|----------|
30+
| 6.x | Current | Nov 2020 | Apr 2023 _(minimum)_ | 4 | 4.x |
31+
| 5.x | Active LTS | Jun 2019 | Apr 2023 | 3, 4 | 3.x, 4.x |
32+
| 4.x | Maintenance LTS | Nov 2018 | Apr 2021 | 3, 4 | 3.x, 4.x |
33+
2234
## Creating a MongoDB data source
2335

2436
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.
@@ -38,32 +50,6 @@ const config = {
3850
};
3951
```
4052

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

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

137123
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`.
138124

139-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
140-
141-
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-
163125
### Using the mongodb+srv protocol
164126

165127
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.
@@ -175,19 +137,6 @@ const config = {
175137
};
176138
```
177139

178-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
179-
180-
```javascript
181-
"mydb": {
182-
"connector": "mongodb",
183-
"host": "myserver",
184-
"database": "test",
185-
"protocol": "mongodb+srv"
186-
}
187-
```
188-
189-
</details>
190-
191140
Note: the port is not specified when using the `mongodb+srv` protocol and will be ignored if given.
192141

193142
## Security Considerations
@@ -213,47 +162,6 @@ See [LoopBack 4 types](http://loopback.io/doc/en/lb4/LoopBack-types.html) (or [L
213162

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

216-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
217-
218-
## 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-
257165
## Update Operators
258166

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

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

@@ -323,23 +218,6 @@ export class User extends Entity {
323218
}
324219
```
325220

326-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
327-
328-
```js
329-
{
330-
"name": "User",
331-
"base": "PersistedModel",
332-
"idInjection": false,
333-
"options": {
334-
"validateUpsert": true,
335-
"strictObjectIDCoercion": true
336-
},
337-
...
338-
}
339-
```
340-
341-
</details>
342-
343221
### Property scope
344222

345223
This scope would only convert an ObjectId-like string to `ObjectId` with a certain property in the model.
@@ -353,24 +231,6 @@ This scope would only convert an ObjectId-like string to `ObjectId` with a certa
353231
id: string;
354232
```
355233
356-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
357-
358-
```js
359-
"properties": {
360-
{
361-
"id": {
362-
"type": "String",
363-
"id": true,
364-
"required":true,
365-
"mongodb": {"dataType":"ObjectId"}
366-
},
367-
// ..
368-
}
369-
}
370-
```
371-
372-
</details>
373-
374234
Also notice that for RELATIONS, if the primary key/source key has set to enforce ObjectId coercion
375235
(no matter by `strictObjectIDCoercion: true` or `dataType: 'ObjectId'`). The corresponding foreign key will need to have it
376236
set as well to make sure relations work smoothly.
@@ -432,33 +292,6 @@ export class User extends Entity {
432292
}
433293
```
434294
435-
<details><summary markdown="span"><strong>For LoopBack 3 users</strong></summary>
436-
437-
```js
438-
{
439-
"name": "User",
440-
"options": {
441-
"mongodb": {
442-
"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-
462295
{% 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." %}
463296
464297
## Running tests

deps/juggler-v3/package.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

deps/juggler-v3/test.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 4 deletions
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",

test/objectid.test.js

Lines changed: 4 additions & 4 deletions
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)