typescriptnext.jsconvex.dev

Is there a way to get only few selected columns from the Convex database?


This snippet of code fetches all the columns from the table, is there a way to do that, I didn't find any thing in the docs, does someone know a trick or something

const documents = await ctx.db
            .query("documents")
            .withIndex("by_user", (q) => (
                q.eq("userId", userId)
            ))
            .filter((q) => (
                q.eq(q.field("isArchived"), false)
            ))
            .order("desc")
            .collect();

I want to avoid fetching same data multiple times

Docs: https://docs.convex.dev/


Solution

  • Would you like to avoid fetching all columns from the table? There's no API for this currently, you're going to get the entire stored "documents" record.

    You won't be fetching the same data multiple times here, and even if another query gets the same "documents" again, this query will be cached.