MathiasM
Convex Community2y ago
7 replies
Mathias

Query all users based on an Id

I'm working on optimizing a data query process in our application and could use your insight. Currently, I'm faced with a rather inefficient method of fetching all users associated with a specific group. The process involves multiple steps: initially querying for a user to determine their 'activeGroup' and then using this identifier to fetch the group and its associated users. This approach seems overly cumbersome and I'm convinced there must be a more direct and efficient method.

To give you a clearer picture, here's how our data is structured:

User Document Example:
{
  "about": "",
  "activeGroup": "js73fcztnesqdyddnfxrn5j6056mvtd8",
  "email": "hello@patrick.com",
  "fullName": "Patrick Elvira",
  "imageUrl": "be8746d5-da3a-4a37-923f-467ed7911a84.png",
  "initials": "MRS",
  "status": "active",
  "termsAcceptedAt": "2024-03-06T07:03:45.083Z",
  "userId": "user_3cWkkgNS5bjSv0dfdsdf333jlyDxyZHfCgu",
  "groupIds": ["js7b4ck0xxrhhaxw2kbzyjpv896mswee", "js73fcztnesqdyddnfxrn5j6056mvtd8"]
}


Group Document Example:

{
  "about": "This is an about section for the group.",
  "email": "group@group.io",
  "logo": "45dcbf78-1461-400e-83c5-b466a8fb9d61.png",
  "name": "Group",
  "ownerId": "user_3cWkkgNS5bjds0HjldfxyZ43Cgu"
}


My goal is to simplify this process, ideally querying for all users within a specific group directly, without the preliminary steps currently required. I'm searching for any resources or advice you may have on achieving this more effectively. Do you know of any methods or tools that could facilitate a more streamlined approach to querying these relationships?

Thanks in advance for your help!
Was this page helpful?