Skip to content

Commit

Permalink
refactor: prevent params fields from being used as options in find me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
gusth-sa committed Aug 18, 2023
1 parent 5ab64c0 commit 81ce7b5
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 @@ -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,
Expand Down

0 comments on commit 81ce7b5

Please sign in to comment.