Meteor find if value exists

Hi,

I want to make a querie with multiple options if they exists.

Has can be seen in the picture, image if i choose two dropdown menus, i want to search only using two fields (filters in the querie) in Mongodb, or if i choose all, for example, i want to filter the querie to match the documents with all those fields.

Thanks,
sfm

If i am understanding your question correctly just create an object an place it into the find query.

Example:
var obj = {country: {$nin: ["Peru", "Italy"]}}

and then place that object into your query like so:

Users.find(obj).fetch()

You can make the object as complicated as you want to.

In any dropdown above if i choose a field i´ll get a value. I want to use that value and the problem is the values that were not chosen will be part of my query. Meaning that all 6 drop down are gonna be variables to my queries and some of them aren’t choosed so the value would be undefined. How can i build a query with such variables?

thanks, after some reading and your example I figured out

1 Like