Understand the new mongo identifier and use it with an iron router

I have a simple mail route that searches for a message _id. The problem is that the assistant pathForcreates this way:

ObjectID("52e16453431fc2fba4b6d6a8")

I assume that the mongoDB insert has been changed, and now the object _idcontains another object inside it called _str.

Here is my route:

this.route("post", {
        path: "/post/:_id",

        waitOn:function(){
            NProgress.start();
            Meteor.subscribe("Teams");
        },

        before: function () {
            NProgress.done();
        },

        data: function () {
            return Posts.findOne({_id: this.params._id});
        }
    });

He is currently creating hrefas:

 post/ObjectID("52e16453431fc2fba4b6d6a8")

clicking on it opens the url

post/ObjectID("52e16453431fc2fba4b6d6a8") 

However, I get a "NotFound" template instead of a message.

How can i fix this?

+4
source share
2 answers

pathFor 'post', ObjectId 52e16453431fc2fba4b6d6a8 ObjectId('52e16453431fc2fba4b6d6a8')

- pathFor 'post' _id=this._id.toHexString

,

return Posts.findOne({ _id: new Meteor.Collection.ObjectID(this.params._id)});

+6

:

this.route("post", {
    path: "/post/:stringId",

    waitOn:function(){
        NProgress.start();
        Meteor.subscribe("Teams");
    },

    before: function () {
        NProgress.done();
    },

    data: function () {
        Post = Posts.findOne({_id: Meteor.ObjectId(this.params.stringId)});
    }
});

, post/52e16453431fc2fba4b6d6a8, .

- objectid , .

, , , .

0

Source: https://habr.com/ru/post/1523409/


All Articles