OccultSlolem
OccultSlolem2y ago

array contains filters

How can I filter a table row for an array containing a certain value? Something like
const { subject } = id;
const orgs = await ctx.db
.query('organizations')
.filter(q => q.contains(q.field('authorizedUIDs'), subject)) // Something like this
.collect();
const { subject } = id;
const orgs = await ctx.db
.query('organizations')
.filter(q => q.contains(q.field('authorizedUIDs'), subject)) // Something like this
.collect();
2 Replies
lee
lee2y ago
we have been considering adding a q.contains to the filter language. for now you can do the filter in javascript/typescript, which is almost equivalent at runtime -- the js runs close to the database so it's just as fast, and looks at the same amount of data as a built-in filter.
const orgs = (await ctx.db
.query('organizations')
.collect())
.filter(doc => doc.authorizedUIDs.includes(subject))
const orgs = (await ctx.db
.query('organizations')
.collect())
.filter(doc => doc.authorizedUIDs.includes(subject))
OccultSlolem
OccultSlolemOP2y ago
Awesome, thanks. A contains filter would make the filter language feel a bit more natural in this edge case. Thanks for your help.

Did you find this page helpful?