- 
                Notifications
    
You must be signed in to change notification settings  - Fork 58
 
Open
Description
I was trying to perform the equivalent operation of a UNION between between rows coming from a JOIN and rows coming from a simple query. The two sets of rows had identical set of columns but the operation fails.
const userMemberships = stream(ctx.db, schema).query("channelMembers").withIndex("by_user", (q) => q.eq("userId", userId))
const privateChannels = userMemberships
      .flatMap(async (membership) => stream(ctx.db, schema)
        .query("channels")
        .withIndex("by_isPublicInWorkspace", q => q.eq("isPublic", false).eq("workspaceId", workspaceId))
        .filterWith(async (q) => q._id === membership.channelId)
        ,
        ['isPublic', "workspaceId"]
      )
const publicChannels = stream(ctx.db, schema).query("channels").withIndex("by_isPublicInWorkspace", (q) => q.eq("isPublic", true).eq("workspaceId", workspaceId))
return mergedStream([privateChannels, publicChannels], [INDEX_FIELDS])Wathever I tried to put in INDEX_FIELDS I had this error:
7/17/2025, 10:35:27 PM [CONVEX Q(channels:listByUserMembership)] Uncaught Error: indexFields must be some sequence of fields the stream is ordered by: ["_creationTime","_id"], ["workspaceId","userId","_creationTime","_id","_id"] (2 equality fields)
I believe that flatmaps brings along the index_fields of the parent table, making it impossible to reconcile with the index_fields of the child table INDEX_FIELDS(parent+child) != INDEX_FIELDS(child),
Honestly I would be lying if I'd say that I understand what is happening here but I strongly feel that this should be possible
Metadata
Metadata
Assignees
Labels
No labels