Dale12
Dale12

Reputation: 30

How to filter minimongo collection with more parameters in meteor

I need help with filtering reactively minimongo collection with 3+ parameters. Firs, I have loaded minimongo from server's mongo collection with publish/subscribe. Now, I want to filter that collection and let user see only objects from collection that are same like filters. First of all I have search query filter that checks if input string is same as some filed in collection:

Job.find({  $or: [ { Name: regex }, { Description: regex }, ]});

This part is doing his job well. And now second filter: I have field in object that is true if that particular job is remote friendly and false if it is not, I wanted to if user enables that filter he only see just remote friendly job positions, and if he disables that, he can see all jobs available ( + search query of course):

if (remoteQuery === true ) {
        return Job.find({  $or: [ { Name: regex }, { Description: regex }, ]  , Remote: true});
}

This is working, but it is bad way for doing this. And now biggest problem comes with last filter: I have one more field that is storing "job" (collection object) type. Type can be 1, 2 , 3 or 4. So how could I say to minimongo e.g. "Show only jobs that have "Front-end" inside (search query), that are remote friendly, and have third filter 2 and 3 inside"

Job.find({  $or: [ { Name: "Front-end"}, { Description: "Front-end"}, ]  , Remote: true, positionType: [2,3],}); 

Something like this? Thanks!

Upvotes: 0

Views: 283

Answers (1)

ghybs
ghybs

Reputation: 53225

Sounds like you are looking for the MongoDB query $in operator:

The $in operator selects the documents where the value of a field equals any value in the specified array.

Therefore your 3rd query could look like:

Job.find({
    positionType: {
        $in: [2, 3] // Matches documents where `positionType` is either 2 or 3
    },
    // Other conditions…
});

Upvotes: 2

Related Questions