Search code examples
mongodbmeteoriron-router

howto route with collection's param in iron router Meteor JS


It is common way to route collection News as below using _id params,

this.route('newsPage', {
path:'/news/:_id',
data: function(){ return News.findOne(this.params._id);}
});

when News collection is declared like this { "_id" : ObjectId("51a7dc7b2cacf40b79990bf7"), "name" : myName, "body": mybody } I am trying to route like this.

this.route('newsPage', {
path:'/news/:name',
data: function(){ return News.findOne(this.params.name);}
});

so I can route /news/myName. in MongoDB _id is unique, my News collections name params are unique too. Is it possible to route like this.


Solution

  • data: function(){ return News.findOne({name: this.params.name});}