Skip to content

Commit

Permalink
Merge pull request #2 from baronapp/zv/simplify-paginated-query
Browse files Browse the repository at this point in the history
Send simpler paginated queries to Mongo with no next/prev parameters
  • Loading branch information
Zack Voase authored Mar 31, 2021
2 parents b0ad3ee + 309a98d commit 3b8aae6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ module.exports = async function(collection, params) {
// https://www.npmjs.com/package/mongoist#cursor-operations
const findMethod = collection.findAsCursor ? 'findAsCursor' : 'find';

const query = collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields);
// If cursorQuery is empty, we can just send `params.query` as-is with the same result.
const predicate = Object.keys(cursorQuery).length === 0 ? params.query : { $and: [cursorQuery, params.query] };
const query = collection[findMethod](predicate, params.fields);

/**
* IMPORTANT
Expand Down

0 comments on commit 3b8aae6

Please sign in to comment.