David AlonsoD
Convex Community2y ago
3 replies
David Alonso

Nested field indexes and query filters

Hello! I am trying to run this query:

const block = await context.db
        .query("blocks")
        .withIndex("by_parent_grid_idx", (q) =>
        q.eq("parentBlockId", parentBlockId).eq("properties.gridLayout.i", gridLayout.i)
         )
        .unique();


But I'm not able to create an index for properties.gridLayout.i
I'm surprised this query also doesn't return any results

const block = await context.db
        .query("blocks")
  .withIndex("by_parent", (q) => q.eq("parentBlockId", parentBlockId))
        .filter((q) => q.eq("properties.gridLayout.i", gridLayout.i))
.unique();


the schema of blocks is a union and not all objects inside the union have a guaranteed gridLayout property. Just wondering if this is expected so that I know if I'm doing something wrong
Was this page helpful?