Bruno Prado
Bruno Prado3w ago

Hello, I'm having a problem with my `tenants`.

When search for a product, I'm getting products from another tenant.
export default query({
handler: async (ctx) => {
console.log("Write and test your query function here!");
return await ctx.db.query("products").withSearchIndex('by_name_and_tenant_and_deleted_and_is_active', (q) =>
q.search('name', "brigadeiro").eq('tenantId', "nx7bgjj6ras1r2ee9xnw6vv2nd7njke6" as any).eq('deleted', false).eq('isActive', true)
)
.take(10)
},
})
export default query({
handler: async (ctx) => {
console.log("Write and test your query function here!");
return await ctx.db.query("products").withSearchIndex('by_name_and_tenant_and_deleted_and_is_active', (q) =>
q.search('name', "brigadeiro").eq('tenantId', "nx7bgjj6ras1r2ee9xnw6vv2nd7njke6" as any).eq('deleted', false).eq('isActive', true)
)
.take(10)
},
})
[
{
_creationTime: 1755105877167.9624,
_id: "md7cfcf36pw857stmpdzxm3n8s7nj18a",
addons: [],
basePrice: 3.5,
category: "Doces unitários",
categoryId: "m17ft4pg7hd4kf97nkx2t8gap17nkszh",
cost: 0,
deleted: false,
description:
"Massa de brigadeiro de chocolate envolta em confeitos de açúcar em cores variadas.",
extras: [],
images: ["kg2dgpm4q2twfxfkqs6pxy5kfn7nkev9"],
isActive: true,
lastUpdated: 1755105877168,
name: "Brigadeiros unitários",
options: [],
recipes: [],
tenantId: "nx7afykk0qpbrk08w51yhe9rhn7njh79",
},
{
_creationTime: 1755105698925.9456,
_id: "md7d3pfqcqk4bcabvvq33f9tss7nk27c",
addons: [],
basePrice: 5,
category: "Doces unitários",
categoryId: "m17ft4pg7hd4kf97nkx2t8gap17nkszh",
cost: 0,
deleted: false,
description:
"Delicioso brigadeiro com granulado belga. Cerca de 20g.",
extras: [],
images: ["kg216es4ps5fd3pgj101ae2da97nkjqm"],
isActive: true,
lastUpdated: 1755105826778,
name: "Brigadeiros belga da Lili",
options: [],
recipes: [],
tenantId: "nx7afykk0qpbrk08w51yhe9rhn7njh79",
},
]
[
{
_creationTime: 1755105877167.9624,
_id: "md7cfcf36pw857stmpdzxm3n8s7nj18a",
addons: [],
basePrice: 3.5,
category: "Doces unitários",
categoryId: "m17ft4pg7hd4kf97nkx2t8gap17nkszh",
cost: 0,
deleted: false,
description:
"Massa de brigadeiro de chocolate envolta em confeitos de açúcar em cores variadas.",
extras: [],
images: ["kg2dgpm4q2twfxfkqs6pxy5kfn7nkev9"],
isActive: true,
lastUpdated: 1755105877168,
name: "Brigadeiros unitários",
options: [],
recipes: [],
tenantId: "nx7afykk0qpbrk08w51yhe9rhn7njh79",
},
{
_creationTime: 1755105698925.9456,
_id: "md7d3pfqcqk4bcabvvq33f9tss7nk27c",
addons: [],
basePrice: 5,
category: "Doces unitários",
categoryId: "m17ft4pg7hd4kf97nkx2t8gap17nkszh",
cost: 0,
deleted: false,
description:
"Delicioso brigadeiro com granulado belga. Cerca de 20g.",
extras: [],
images: ["kg216es4ps5fd3pgj101ae2da97nkjqm"],
isActive: true,
lastUpdated: 1755105826778,
name: "Brigadeiros belga da Lili",
options: [],
recipes: [],
tenantId: "nx7afykk0qpbrk08w51yhe9rhn7njh79",
},
]
Is this an expected behaviour? What am I doing wrong?
4 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!
erquhart
erquhart3w ago
This is a known issue, you can track here: https://github.com/get-convex/convex-js/issues/56
GitHub
Only final filter field is honored in search index · Issue #56 · ...
Support thread reference: https://discord.com/channels/1019350475847499849/1393596083506253915 Given this schema: export default defineSchema({ numbers: defineTable({ search: v.optional(v.string())...
Bruno Prado
Bruno PradoOP3w ago
Thanks mate, might post there too.
erquhart
erquhart3w ago
Really odd, I just realized I'm using search index in my own application code, and using indexes for authorization 😅 . But I'm playing with my implementation and not able to reproduce this bug there. The reproduction repo still has it.

Did you find this page helpful?