#s
3 messages · Page 1 of 1 (latest)
Hi @oak tendon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
It depends what you’re doing:
-
If you already have a document’s ID and just need that one document,
ctx.db.getis the recommended best practice. It’s a fast point lookup and avoids building a query at all. [Document IDs; Reading data]const user = await ctx.db.get("users", userId); -
Use
ctx.db.querywhen you need to read multiple documents or filter/order by fields (often via indexes). [Reading data]const messages = await ctx.db .query("messages") .withIndex("by_channel", q => q.eq("channel", channelId)) .collect();