burnstony#1975
burnstony#197510mo ago

query return only one column

is it possible for a query to just return the id I am loading a bunch of data in one function but than getting an error because the check if data already exists is reading to much data I think Too many bytes read in a single function execution can I just get the _id back instead of reading the entire document
3 Replies
ballingt
ballingt10mo ago
It's not today but we recognize this would be useful. Do you have an index on the check that the data already exists?
Michal Srb
Michal Srb10mo ago
Yeah, this is likely caused by a lack of index (loading too many documents), not by the individual documents themselves being large
burnstony#1975
burnstony#1975OP10mo ago
export const patchPodcastRssJson = mutation({ args: { id: v.id("podcast"), rss_json: v.any(), }, handler: async (ctx, args) => { const { id, rss_json } = args; const items = rss_json.rss.channel.item const max_episode = items.length ctx.db.patch(id, { number_of_episodes: max_episode }) for (const [index, item] of rss_json.rss.channel.item.entries()) { const e_n = Math.ceil(max_episode - index) console.log("podcast_id:%s episode_number:%", args.id, e_n) const episode = await ctx.db.query("episode") .withIndex("podcast_episode_number") .filter((q) => q.and(q.eq(q.field("podcast_id"), args.id), q.eq(q.field("episode_number"), e_n))) .unique() // patch or insert if (episode) { ctx.db.patch(episode._id, { podcast_id: args.id, episode_number: Math.ceil(max_episode - index), body: item }) } else { ctx.db.insert("episode", { podcast_id: args.id, episode_number: Math.ceil(max_episode - index), body: item }) // } } the body can be large, but I think the problem is that its looping over all the episodes for a podcast in one transaction it works fine if it just inserts, but it blows up if its running the query too looks like my syntax is wrong const episode = await ctx.db.query("episode") .withIndex("podcast_episode_number") .filter((q) => q.and(q.eq(q.field("podcast_id"), args.id), q.eq(q.field("episode_number"), e_n))) change it to this and now it works fine const episode = await ctx.db.query("episode") .withIndex("podcast_episode_number", (q) => q.eq("podcast_id", args.id).eq("episode_number", e_n)) .unique()

Did you find this page helpful?