Skip to content

Commit 65be1c4

Browse files
authored
Merge pull request #49 from Marsup/feat/mongodb-4.x
Bump mongodb to 4.x
2 parents 4de4fb1 + 3bbd137 commit 65be1c4

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
os: [ubuntu]
15-
node: ['*', '14', '12', '10']
15+
node: ['*', '16', '14', '12']
1616
hapi: ['20', '19', '18']
17-
exclude:
18-
- node: 10
19-
hapi: 19
20-
- node: 10
21-
hapi: 20
2217
include:
2318
- os: ubuntu
2419
node: '*'

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Mongodb = require('mongodb');
44
const Joi = require('joi');
55

66
const MongoClient = Mongodb.MongoClient;
7-
const ObjectID = Mongodb.ObjectID;
7+
const ObjectID = Mongodb.ObjectId;
88

99
const singleOption = Joi.object({
1010
url: Joi.string().default('mongodb://localhost:27017/test'),
@@ -26,7 +26,8 @@ exports.plugin = {
2626

2727
const expose = {
2828
lib: Mongodb,
29-
ObjectID
29+
ObjectID,
30+
ObjectId: ObjectID
3031
};
3132

3233
const connect = async function (connectionOptions) {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"url": "https://github.com/Marsup/hapi-mongodb/issues"
2020
},
2121
"engines": {
22-
"node": ">= 8"
22+
"node": ">= 12"
2323
},
2424
"dependencies": {
2525
"joi": "^17.2.1",
26-
"mongodb": "^3.2.3"
26+
"mongodb": "^4.0.1"
2727
},
2828
"devDependencies": {
2929
"@hapi/code": "^8.0.2",

test/connection.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ describe('Hapi server', () => {
5454
await server.register({
5555
plugin: require('../'),
5656
options: {
57-
url: 'mongodb://localhost:27018'
57+
url: 'mongodb://localhost:27018',
58+
settings: {
59+
serverSelectionTimeoutMS: 500
60+
}
5861
}
5962
});
6063
}
@@ -97,7 +100,7 @@ describe('Hapi server', () => {
97100
});
98101
});
99102

100-
it('should log configuration upon successfull connection, obscurifying DB password', async () => {
103+
it('should log configuration upon successful connection, obscurifying DB password', async () => {
101104

102105
let logEntry;
103106
server.events.once('log', (entry) => {
@@ -111,7 +114,7 @@ describe('Hapi server', () => {
111114

112115
Mongodb.MongoClient.connect = originalConnect;
113116
expect(url).to.equal('mongodb://user:[email protected]:27017');
114-
expect(options).to.equal({ poolSize: 11 });
117+
expect(options).to.equal({ maxPoolSize: 11 });
115118
connected = true;
116119
return Promise.resolve({ db: () => 'test-db' });
117120
};
@@ -121,7 +124,7 @@ describe('Hapi server', () => {
121124
options: {
122125
url: 'mongodb://user:[email protected]:27017',
123126
settings: {
124-
poolSize: 11
127+
maxPoolSize: 11
125128
}
126129
}
127130
});
@@ -131,7 +134,7 @@ describe('Hapi server', () => {
131134
channel: 'app',
132135
timestamp: logEntry.timestamp,
133136
tags: ['hapi-mongodb', 'info'],
134-
data: 'MongoClient connection created for {"url":"mongodb://user:******@example.com:27017","settings":{"poolSize":11}}'
137+
data: 'MongoClient connection created for {"url":"mongodb://user:******@example.com:27017","settings":{"maxPoolSize":11}}'
135138
});
136139
});
137140

@@ -142,7 +145,7 @@ describe('Hapi server', () => {
142145
options: {
143146
url: 'mongodb://localhost:27017',
144147
settings: {
145-
poolSize: 10
148+
maxPoolSize: 10
146149
}
147150
}
148151
});
@@ -320,12 +323,12 @@ describe('Hapi server', () => {
320323

321324
await server.initialize();
322325

323-
expect(server.plugins['hapi-mongodb'].client.isConnected()).to.be.true();
326+
expect(server.plugins['hapi-mongodb'].client.topology.isConnected()).to.be.true();
324327

325328
await server.stop();
326329
await Hoek.wait(100); // Let the connections end.
327330

328-
expect(server.plugins['hapi-mongodb'].client.isConnected()).to.be.false();
331+
expect(server.plugins['hapi-mongodb'].client.topology).to.be.undefined();
329332
});
330333

331334
it('should logs errors on disconnect', async () => {
@@ -342,7 +345,7 @@ describe('Hapi server', () => {
342345

343346
await server.initialize();
344347

345-
expect(server.plugins['hapi-mongodb'].client.isConnected()).to.be.true();
348+
expect(server.plugins['hapi-mongodb'].client.topology.isConnected()).to.be.true();
346349
const closeStub = Sinon.stub(server.plugins['hapi-mongodb'].client, 'close').callsFake((cb) => {
347350

348351
setTimeout(cb, 0, new Error('Oops'));

0 commit comments

Comments
 (0)