Skip to content

Commit

Permalink
refactor: prevent param fields from being used as options in find method
Browse files Browse the repository at this point in the history
  • Loading branch information
gusth-sa committed Aug 19, 2023
1 parent 9f43bec commit 3c8030a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
7 changes: 1 addition & 6 deletions test/support/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3c8030a

Please sign in to comment.