wrux
wrux
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
Ok so here's an example schema:
const schema = defineSchema({
...authTables,
skills: defineTable({
title: v.string(),
}),
jobs: defineTable({
title: v.string(),
clientId: v.id('users'),
skills: v.optional(v.array(v.id('skills'))),
}).index('by_clientId', ['clientId']),
});
const schema = defineSchema({
...authTables,
skills: defineTable({
title: v.string(),
}),
jobs: defineTable({
title: v.string(),
clientId: v.id('users'),
skills: v.optional(v.array(v.id('skills'))),
}).index('by_clientId', ['clientId']),
});
Then on the frontend I'm listing all jobs and on the sidebar showing filters for skills. Let's say I select Designer and Developer, the query should filter jobs with those skills inside the skills key on the jobs object. The suggested query to fetch everything and then filter in JS isn't going to work if we have 100,000 jobs in the DB
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
Ok that's concerning. I'm working on an app and before asking this question I was filtering my data like the article recommends, by filtering after .collect() . I'm seeing fairly large DB bandwidth usage in local development without much data in the database. I think maybe Convex isn't aimed at my usecase
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
Can you give an example of a schema and query?
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
Seems like it should be a core feature
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
So is there no plan at all to add functions that allow filtering before .collect()?
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
Ok thanks
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
Is bandwidth considered data going between convex functions and the DB backend? Or is it between the convex function and the client consuming the API?
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
That's going to be using lots of DB bandwidth quota
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
But let's say the posts object has a lot of data, then isn't it going to send down a all of that data for in the records we don't need?
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
.arrayIncludes() would be nice
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
There's a example of code that would be nice if it's possible in that article:
export const postsWithTag = query({
args: { tag: v.string() },
handler: async (ctx, args) => {
return await ctx.db
.query("posts")
// Doesn't work because q.arrayIncludes doesn't exist.
.filter((q) => q.arrayIncludes(q.field("tags"), args.tag)
.collect();
},
});
export const postsWithTag = query({
args: { tag: v.string() },
handler: async (ctx, args) => {
return await ctx.db
.query("posts")
// Doesn't work because q.arrayIncludes doesn't exist.
.filter((q) => q.arrayIncludes(q.field("tags"), args.tag)
.collect();
},
});
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
Is filtering array values in the product roadmap? Seems like it would be a great addition
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
Interesting, ok
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
What is the reccomended route though?
37 replies
CCConvex Community
Created by wrux on 2/9/2025 in #support-community
Query, filtering array of IDs
@Lee So is the recommended solution to over-fetch and then remove the unwanted values?
37 replies
CCConvex Community
Created by wrux on 2/6/2025 in #support-community
Best solution for checks like unique username
I ended up using convex.query yeah
7 replies
CCConvex Community
Created by wrux on 2/6/2025 in #support-community
Best solution for checks like unique username
Yeah I have that exact endpoint, but would you place the query into a Zod validator, or into the form on submit function? I don't want to overload the API for no reason so I'm thinking in the on submit. Also, what's the recommended way to jsut fire a regular await fetch request with Convex?
7 replies
CCConvex Community
Created by wrux on 2/6/2025 in #support-community
Best solution for checks like unique username
Would it be best to add the check directly into the Zod schema?
7 replies