noConvexCollectInQuery (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noConvexCollectInQuery - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- This rule belongs to the following domains:
- Sources:
- Same as
@convex-dev/no-collect-in-query
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noConvexCollectInQuery": "error" } } }}Description
Section titled “Description”Disallow loading every result of a Convex database query with .collect().
As a table grows, .collect() returns more and more documents, until the query fails
at the Convex query limits.
Use .take() or .paginate() instead.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”const messages = await ctx.db.query("messages").collect();code-block.js:1:49 lint/nursery/noConvexCollectInQuery ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This database query loads every matching document with .collect().
> 1 │ const messages = await ctx.db.query("messages").collect();
│ ^^^^^^^^^
2 │
ℹ A query that returns many documents uses a lot of bandwidth, makes mutations more likely to conflict, and fails once it reaches the Convex query limits.
ℹ Use .take() to load only the first few documents, or .paginate() to load them one page at a time. If this query always returns a small number of documents, suppress this diagnostic with a biome-ignore comment.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
const messages = await ctx.db .query("messages") .withIndex("by_channel", (q) => q.eq("channel", channel)) .order("desc") .collect();code-block.js:5:6 lint/nursery/noConvexCollectInQuery ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This database query loads every matching document with .collect().
3 │ .withIndex("by_channel", (q) => q.eq("channel", channel))
4 │ .order("desc")
> 5 │ .collect();
│ ^^^^^^^^^
6 │
ℹ A query that returns many documents uses a lot of bandwidth, makes mutations more likely to conflict, and fails once it reaches the Convex query limits.
ℹ Use .take() to load only the first few documents, or .paginate() to load them one page at a time. If this query always returns a small number of documents, suppress this diagnostic with a biome-ignore comment.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
const latest = await ctx.db.query("messages").order("desc").take(10);const page = await ctx.db.query("messages").paginate(paginationOpts);const first = await ctx.db.query("messages").first();Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.