fix(db-mongodb): db.find default limit to 0 (#8376)

Fixes an error anytime a `db.find` is called on documents with joins
without a set `limit` by defaulting the limit to 0.
This commit is contained in:
Dan Ribbens
2024-09-23 16:31:50 -04:00
committed by GitHub
parent 19e2f10f4b
commit dc69e2c0f6
3 changed files with 31 additions and 4 deletions

View File

@@ -15,7 +15,7 @@ export const find: Find = async function find(
{
collection,
joins = {},
limit,
limit = 0,
locale,
page,
pagination,

View File

@@ -111,9 +111,10 @@ export const buildJoinAggregation = async ({
input: `$${as}.docs`,
},
}, // Slicing the docs to match the limit
[`${as}.hasNextPage`]: {
$gt: [{ $size: `$${as}.docs` }, limitJoin || Number.MAX_VALUE],
}, // Boolean indicating if more docs than limit
[`${as}.hasNextPage`]: limitJoin
? { $gt: [{ $size: `$${as}.docs` }, limitJoin] }
: false,
// Boolean indicating if more docs than limit
},
},
)