objectId from url to match with one in the mongo using meteorjs

China☆狼群 提交于 2019-12-22 10:59:23

问题


I am new to meteor js. I got the id from url but i am failing to match it with the id in the mongodb. can any help me

Router.map(function () {
  this.route('post', {
    template:'viewpost',
    path: '/post/:_id',
    data: function () {
     var id = new ObjectID(this.params._id);
      return Tasks.findOne({_id: id});

    }

  });

回答1:


I suspect you want to return a single task? You access the _id from this.params where this refers to the router.

Router.map(function () { 
        this.route('post', { 
            template:'viewpost', 
            path: '/post/:_id', 
            data: function () { 
                return Tasks.findOne(this.params._id);
            }
});

In your template you can start referring to the task because it will be the data context for the template;

<p>{{description}}</p>

Assuming you have a description field in your Tasks Collection.



来源:https://stackoverflow.com/questions/28606616/objectid-from-url-to-match-with-one-in-the-mongo-using-meteorjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!