Filter MongoDB Results To Client


#1

Hi guys, I’m just wondering how I can filter results that are pulled from my Meteor Collection just like a layered navigation that you see on many eCommerce websites.

For example I currently have this simple collection:

Vehicles = new Mongo.Collection("vehicles");

if (Meteor.isClient) {
  Template.body.helpers({
    vehicles: function () {
      return Vehicles.find({});
    }
  });
}

So this is the type of thing I am trying to achieve:

http://www.jct600.co.uk/used-car-results.aspx?COGBodyCategory=Nearly+New%2CUsed&

NOTE: press Filter Results.

I am trying to filter the collection based on the values that each document has in my MongoDB. So if a website user selects ‘Audi’ I would like to show all of the documents with that value in it.

Does anybody have any examples of where this might have been done before?

Thanks, Nick


#2
return Vehicles.find({brand: Session.get('brand')});

And when you change a filter input do a Session.set off course. This works because it’s reactive variable.

Further on you want to look at reactive-dict if you get how this works. That will allow you to writer cleaner code for it.

Btw. you are now doing this on the client. That will work with a limited amount of data. When it becomes more you want to do it in subscribe. https://www.discovermeteor.com/blog/understanding-meteor-publications-and-subscriptions/


#3

return Vehicles.find({vehicles: this._id});