ibrahimyaacob
ibrahimyaacob3w ago

how do i skip indexed query field

it seems like i am forced to follow the order of the defined index in schema. I dont want to use filter because some of the query are hitting too many bytes read error. please help schema.ts
.index("organizationId_postedAt_experiment", [
"organizationId",
"isOwner",
"statusLabel",
"postedAt",
])
.index("organizationId_postedAt_experiment", [
"organizationId",
"isOwner",
"statusLabel",
"postedAt",
])
function.ts
let query = ctx
.table(
"socialPostComments",
"organizationId_postedAt_experiment",
(q) => {
let indexedQuery = q
.eq("organizationId", args.organizationId)
.eq("isOwner", false) // i want to skip this, make it optional
.eq("statusLabel", "LIVE");

if (args.date) {
return indexedQuery
.gte("postedAt", args.date.from)
.lte("postedAt", args.date.to);
}

return indexedQuery;
},
)
.order("desc");
let query = ctx
.table(
"socialPostComments",
"organizationId_postedAt_experiment",
(q) => {
let indexedQuery = q
.eq("organizationId", args.organizationId)
.eq("isOwner", false) // i want to skip this, make it optional
.eq("statusLabel", "LIVE");

if (args.date) {
return indexedQuery
.gte("postedAt", args.date.from)
.lte("postedAt", args.date.to);
}

return indexedQuery;
},
)
.order("desc");
6 Replies
Convex Bot
Convex Bot3w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
lee
lee3w ago
you can't skip fields in an index (see https://stack.convex.dev/databases-are-spreadsheets for why). what you can do is create multiple indexes with the fields in different orders.
Databases are Spreadsheets
I want to share my mental model of databases: - Databases are just big spreadsheets - An index is just a view of the spreadsheet sorted by one or mor...
ibrahimyaacob
ibrahimyaacobOP3w ago
What if i have 4 to 5 more optional field that i want to filter ? Do i need to do index for all combinations??
lee
lee3w ago
yes, if you want them to be efficient. i would pick the most important combinations and use filters for the rest
ibrahimyaacob
ibrahimyaacobOP3w ago
thanks for the suggestion. now i've pushed the new few indexed fields to production and convex deploy command is taking too long, i assume its because we have too many rows. is there a way for me to see the progress (on vercel)? im gonna add few more indexed fields later
ibrahimyaacob
ibrahimyaacobOP3w ago
its been 15 minutes like this
No description

Did you find this page helpful?