#Query where a list includes
1 messages · Page 1 of 1 (latest)
Hi @kind flax. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the knowledge sources provided, Convex does not directly support a contains or includes operator for querying lists. However, you can achieve this by fetching the entire list and then filtering it in your application code.
Here's an example of how you might do this:
export default query(async (ctx) =>
(await ctx.db.query("messages").collect())
.filter(m => m.content.includes('userId'))
)
In this example, messages is the name of the collection you're querying, content is the field that contains the list, and 'userId' is the user ID you're looking for. Replace these with your actual collection name, field name, and user ID.
Please note that this approach fetches the entire collection and then filters it in your application, which might not be efficient for large collections. For more efficient querying, you might want to consider structuring your data in a way that allows you to use Convex's built-in query operators.