I have three buttons that display different types of information
- View all (i.e., news AND events)
- news only
- events only
Status: Filtering ONLY news OR events works. But how can I view both?
My problem lies in writing a MongoDB query in combination with a session variable. The commented out lines show a failed attempt. In my unsuccessful approach, I tried to include more in the session value by adding the word "type." However, this caused all queries to break.
Here is my js-file:
Template.newsEvents.helpers({
newsEventsData: function () {
// return NewsEvents.find({Session.get('newsEventsView')}, {sort: {createdAt: -1}, limit: 3});
return NewsEvents.find({type: Session.get('newsEventsView')}, {sort: {createdAt: -1}, limit: 3});
}
});
Template.newsEvents.events({
'click #js-seeAll': function (evt, tpl) {
//Session.set('newsEventsView', '$or: [ { type: "news" }, { type: "event" } ]');
},
'click #js-seeNews': function (evt, tpl) {
//Session.set('newsEventsView', 'type: "news"');
Session.set('newsEventsView', 'news');
},
'click #js-seeEvents': function (evt, tpl) {
//Session.set('newsEventsView', 'type: "event"');
Session.set('newsEventsView', 'event');
}
});
This is how my JSON file looks like:
{
"_id" : "7sLK32LdoLv4NmtMJ",
"title" : "3rd News",
"description" : "Some News",
"type" : "news",
"createdAt" : ISODate("2016-01-18T11:23:36.412Z")
}
Any assistance would be greatly appreciated.