Skip to content

Commit 2f3b052

Browse files
gusth-sahishank
authored andcommitted
refactor: prevent param fields from being used as options in find method
1 parent 28f9219 commit 2f3b052

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/find.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ module.exports = async function(collection, params) {
6565
? COLLECTION_METHODS.FIND_AS_CURSOR
6666
: COLLECTION_METHODS.FIND;
6767

68-
const query = collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields);
69-
7068
// Required to support native mongodb 3+ and keep the backward compatibility with version 2
71-
if (findMethod === COLLECTION_METHODS.FIND) {
72-
query.project(params.fields);
69+
let query;
70+
if (findMethod === COLLECTION_METHODS.FIND_AS_CURSOR) {
71+
query = collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields);
72+
} else {
73+
query = collection[findMethod]({ $and: [cursorQuery, params.query] }).project(params.fields);
7374
}
7475

7576
/**

test/support/db.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ async function db(mongod, driver = null) {
1616
db: await mongoist(uri),
1717
};
1818
}
19-
const [client, dbName] = await Promise.all([
20-
MongoClient.connect(uri, {
21-
useUnifiedTopology: true,
22-
}),
23-
mongod.getDbName(),
24-
]);
19+
const [client, dbName] = await Promise.all([MongoClient.connect(uri), mongod.getDbName()]);
2520
return {
2621
db: client.db(dbName),
2722
client,

0 commit comments

Comments
 (0)