diff --git a/index.js b/index.js index 31999d6..1c6ee04 100644 --- a/index.js +++ b/index.js @@ -4,10 +4,7 @@ const fp = require('fastify-plugin') const { MongoClient, ObjectId } = require('mongodb') function decorateFastifyInstance (fastify, client, options) { - const forceClose = options.forceClose - const databaseName = options.database - const name = options.name - const newClient = options.newClient + const { forceClose, database, name, newClient } = options if (newClient) { // done() is not needed because .close() returns a Promise @@ -35,8 +32,8 @@ function decorateFastifyInstance (fastify, client, options) { } } - if (databaseName) { - mongo.db = client.db(databaseName) + if (database) { + mongo.db = client.db(database) } if (!fastify.mongo) { diff --git a/package.json b/package.json index 42a01e3..4385007 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "database", "connection" ], - "author": "Tomas Della Vedova - @delvedor (http://delved.org)", + "author": "Tomas Della Vedova - @delvedor (https://delvedor.dev)", "license": "MIT", "bugs": { "url": "https://github.com/fastify/fastify-mongodb/issues" @@ -32,15 +32,15 @@ "homepage": "https://github.com/fastify/fastify-mongodb#readme", "devDependencies": { "@fastify/pre-commit": "^2.0.2", - "@types/node": "^20.1.0", - "fastify": "^4.0.0", - "standard": "^17.0.0", + "@types/node": "^20.6.2", + "fastify": "^4.23.2", + "standard": "^17.1.0", "tap": "^16.1.0", "tsd": "^0.29.0" }, "dependencies": { - "fastify-plugin": "^4.0.0", - "mongodb": "^6.0.0" + "fastify-plugin": "^4.5.1", + "mongodb": "^6.1.0" }, "publishConfig": { "access": "public" diff --git a/test/index.test.js b/test/index.test.js index 35edd53..497aea1 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -227,7 +227,7 @@ test('{ url: MONGODB_URL, database: ANOTHER_DATABASE_NAME }', async (t) => { test('{ client: client }', async (t) => { t.plan(6) - const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL, { useNewUrlParser: true, useUnifiedTopology: true }) + const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) t.teardown(client.close.bind(client)) const fastify = await register(t, { client }) @@ -243,7 +243,7 @@ test('{ client: client }', async (t) => { test('{ client: client, database: DATABASE_NAME }', async (t) => { t.plan(8) - const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL, { useNewUrlParser: true, useUnifiedTopology: true }) + const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) t.teardown(client.close.bind(client)) const fastify = await register(t, { client, database: ANOTHER_DATABASE_NAME }) @@ -261,7 +261,7 @@ test('{ client: client, database: DATABASE_NAME }', async (t) => { test('{ client: client, name: CLIENT_NAME }', async (t) => { t.plan(11) - const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL, { useNewUrlParser: true, useUnifiedTopology: true }) + const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) t.teardown(client.close.bind(client)) const fastify = await register(t, { client, name: CLIENT_NAME }) @@ -284,7 +284,7 @@ test('{ client: client, name: CLIENT_NAME }', async (t) => { test('{ client: client, name: CLIENT_NAME, database: ANOTHER_DATABASE_NAME }', async (t) => { t.plan(15) - const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL, { useNewUrlParser: true, useUnifiedTopology: true }) + const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) t.teardown(client.close.bind(client)) const fastify = await register(t, { client, name: CLIENT_NAME, database: ANOTHER_DATABASE_NAME }) @@ -309,7 +309,7 @@ test('{ client: client, name: CLIENT_NAME, database: ANOTHER_DATABASE_NAME }', a }) test('{ client: client } does not set onClose', async (t) => { - const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL, { useNewUrlParser: true, useUnifiedTopology: true }) + const client = await mongodb.MongoClient.connect(NO_DATABASE_MONGODB_URL) t.teardown(client.close.bind(client)) const fastify = Fastify()