Reputation: 656
I'm trying to make a filtered search module with meteor. I want my users to precise their serach by adding filters.
With this :
if(!options.natives.length)
return Meteor.users.find({
'profile.languages.learning': {$in: options.learning}
});
else if(!options.learning.length)
return Meteor.users.find({
'profile.languages.native': {$in: options.native}
});
else if(!options.learning.length && !options.native.length)
return null;
else
return Meteor.users.find({
$or: [
{'profile.languages.native': {$in: options.natives}},
{'profile.languages.learning': {$in: options.learning}}
]
});
return Meteor.users.find({
$and: [
{$or {'profile.languages.native': {$in: options.natives}}, NoMatchingLang},
{'profile.languages.learning': {$in: options.learning}}
]
My problem is that profile.languages.learning
is an array, and I want that at least ONE of it's row matches {$in: options.learning}
.
What do you think is the best way to do so ?
Thanks, David
Upvotes: 0
Views: 48
Reputation: 260
This is actually already handled by $in per the Mongo Docs - if the field contains an array, the selector will match documents that have at least one element matching across both arrays.
Upvotes: 1