It'll be much faster if you do it all in one query rather than making multiple requests to the database. Here's a single query that's more or less equivalent to what you wrote:
categories.map(function (doc) {
return doc.merge(
{"questions":
questions
.filter({category_id:doc("id")})
.sample(doc("max_questions"))
.coerceTo("ARRAY")})
})
Notice I've bound the tables to variables here so categories
is bound to r.table("categories")
.