Corbi-Wan KenobiC
Convex Community12mo ago
9 replies
Corbi-Wan Kenobi

How to tell the query to include specific fields

Instead of returning ALL of the fields in a document I want the query to only include specific fields. When I asked AI to help it said to put a .map function after the .query but when I do that I get a .map is not a function error.

Ideally I want to specify the fields in the query, not in the return. Akin to select firstname, lastname from people where... as opposed to what is happening now which is select * from people where...

What I tried based on AI.
export default query(async (ctx) => { console.log("Write and test your query function here!"); return await ctx.db.query("people").map((person) => ({ nameFirst: person.name_first })).collect(); })

What get - Server Error
Uncaught TypeError: ctx.db.query(...).map is not a function
Was this page helpful?