From 6756f62fbcc25bece506b6f1f4846cea3a18202e 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 7fd32ae..464f0b2 100644 --- a/test/support/db.js +++ b/test/support/db.js @@ -20,12 +20,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,