Hello guys, im trying to create a multi select filter to my NFT collection and im trying to do something like this.
filters: {‘Background’: [‘Normal’, ‘Golden’, ‘Special’], ‘PropertyA’: [‘Value1’,‘Value2’], ‘PropertyB’: [] }
so i was trying to use aggregate.
const pipeline = {
sort: {name: 1},
limit,
skip,
}
const matches = [];
for(const key in filters){
if(filters[key].length > 0)
matches.push({ $in: [key, filters[key]] })
}
// matches = [{ $in: [Background, ['Normal', 'Golden', 'Special'] ] }, { $in: [PropertyA, ['Value1','Value2'] ] }]
query.aggregate({...pipeline, match: {$expr: {$and: matches}}})
output returns [];
expected:
[
{Background : ‘Golden’, PropertyA: ‘Value1’ }
{Background : ‘Golden’, PropertyA: ‘Value2’ }
{Background : ‘Special’, PropertyA: ‘Value1’ }
{Background : ‘Special’, PropertyA: ‘Value2’ }
{Background : ‘Normal’, PropertyA: ‘Value1’ }
]