From 2f3b052e9b0fcfd26fbce546452159771e412ea6 Mon Sep 17 00:00:00 2001 From: gustavo Date: Fri, 18 Aug 2023 16:16:46 -0300 Subject: [PATCH] refactor: prevent param fields from being used as options in find method --- src/find.js | 9 +++++---- test/support/db.js | 7 +------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/find.js b/src/find.js index 1f8c746..97a910b 100644 --- a/src/find.js +++ b/src/find.js @@ -65,11 +65,12 @@ module.exports = async function(collection, params) { ? COLLECTION_METHODS.FIND_AS_CURSOR : COLLECTION_METHODS.FIND; - const query = collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields); - // Required to support native mongodb 3+ and keep the backward compatibility with version 2 - if (findMethod === COLLECTION_METHODS.FIND) { - query.project(params.fields); + let query; + if (findMethod === COLLECTION_METHODS.FIND_AS_CURSOR) { + query = collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields); + } else { + query = collection[findMethod]({ $and: [cursorQuery, params.query] }).project(params.fields); } /** diff --git a/test/support/db.js b/test/support/db.js index 755d70e..ac046a7 100644 --- a/test/support/db.js +++ b/test/support/db.js @@ -16,12 +16,7 @@ async function db(mongod, driver = null) { db: await mongoist(uri), }; } - const [client, dbName] = await Promise.all([ - MongoClient.connect(uri, { - useUnifiedTopology: true, - }), - mongod.getDbName(), - ]); + const [client, dbName] = await Promise.all([MongoClient.connect(uri), mongod.getDbName()]); return { db: client.db(dbName), client,