SrondsS
Convex Community14mo ago
2 replies
Sronds

help me setup a cronjob that loops through my entire user table and updates a number

currently the following code errors out because i have more than 4096 user rows

export const replenishPointsForAllUsers = internalMutation({
  args: {},
  handler: async (ctx) => {
    const userQuery = ctx.db.query('user')

    for await (const user of userQuery) {
      await ctx.db.patch(user._id, {
        points: 100,
      })
    }
  },
})


doesn't seem like indexes would help so not sure how to solve this. i know i should batch the queries but not sure how to do it

here is the specific error i'm getting
Uncaught Error: Too many reads in a single function execution (limit: 4096). Consider using smaller limits in your queries, paginating your queries, or using indexed queries with a selective index range expressions.
Was this page helpful?