Query returns empty in production Next.js
I have a Next.js app integrated with Clerk and deployed on vercel and a query used on server and client side.
export const getLines = query({
args: {
document_id: v.id("documents"),
},
handler: async (ctx, args) => {
const lines = await ctx.db
.query("lines")
.withIndex("by_document_id", (q) => q.eq("document_id", args.document_id))
.collect();
return lines;
},
});
const data = await preloadQuery(api.lines.getLines, {
document_id: id as Id<"documents">,
});
const preloadedLines = usePreloadedQuery(lines);
This works perfect on local development, but on production returns empty even if there are documents on the table (even after refresh).
This does not happens all the time, there are times when the query is not empty. I would say 70/30 being empty 70%.5 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
No client side or server side errors.
Just have to troubleshoot more to understand what's happening. I'd start with logging from the function in dev and production to compare. Log the length of the array returned, log the args to make sure they're what you expect.
Look at logs in your Convex dashboard when running these to see if any other functions are running and causing unexpected changes
I am getting the document id but the result of the fetch is empty. Do not know if the the issue is that functions are cached?
export const getLines = query({
args: {
document_id: v.id("documents"),
},
handler: async (ctx, args) => {
console.log(args.document_id);
const lines = await ctx.db
.query("lines")
.withIndex("by_document_id", (q) => q.eq("document_id", args.document_id))
.collect();
console.log(lines);
return lines;
},

Look at your data in the dashboard. Filter the lines table to only lines with that document id. Then watch the data while you run the function. Should shed some light.