opO
Convex Community7mo ago
6 replies
op

Indexing arrays

Hello,

Not supporting array indexing or filtering is a real pain. Is it a popular opinion or is it just me?

Instead of doing something like:
ctx.db.query('products).withIndex(q => q.inArray('tags', tagId))
or
ctx.db.query('products).filter(q => q.inArray(q.field('tags'), tagId))

Over-fetching and then removing unwanted data is not possible because I have a lot of data and I must use a paginated query.

So I am forced to create a union table productXtag and update it for each product insert/update/delete.

I have multiple cases where I need many-to-many relation and it becomes to be a real nightmare to manage them all.

Why is it not possible to index an array?

This is the first serious pitfall I encounter with Convex. This aside, Convex has the best DX I ever encountered.

--

Here is another concrete and classical example:

I have a categories and a products table.

// My categories:
// A
// ├─ B
// ├─ ├─ C

{
  id: "A"
  parentId: undefined
}

{
  id: "B",
  parentId: "A"
}

{
  id: "C",
  parentId: "B"
}

// I also have a product:

{
  categoryId: "C",
  // it could have been:
  // categoryIds: ["A", "B", "C"],
  name: "My product"
}


--> I need an efficient way to get all paginated products in category
A
, including all products in its descendants categories (
B
, C).
Was this page helpful?