raul.spR
Convex Community2y ago
4 replies
raul.sp

getting random "n" entries from a table with db query

export const getQuestionsWithSession = mutation({
  args: {},
  handler: async (ctx, _) => {
    const random_questions = await ctx.db.query("session_question").take(5);
    // const id = await ctx.db.insert("session_question", { text: "" });
  },
}); 
Lets say this " const random_questions = await ctx.db.query("session_question").take(5); " is where i want to get random 5 entries from table "session_question" . I am sure there are other hacky ways using sort, slice. Is there any convex native way of getting random entries from a table ?
Was this page helpful?