DevStronauTD
Convex Community2y ago
4 replies
DevStronauT

How can we do advanced querying on nested arrays ??

I've created this schema for one of my documents

export const DocumentColumns = {
title: v.string(),
userId: v.string(),
content:v.string(),
collaborators: v.optional(
v.array(
v.object({
name: v.string(),
id: v.string(),
imgUrl: v.string(),
})
)
),
};

How can we query all the documents by matching some of the filed values of collaborator field in the collaborators array ??

Just like we do in mongoDb like this!!
const documents = await Documents.find({ "$documents.name": "any" }).exec()

Or if this is not possible than how can we acheive the same using convex queries? do we need to fetch all the documents from our DB at first and then manually do filtering of documents?

Appreciate any help here!

cc: @ballingt @Michal Srb
Was this page helpful?