understand new mongo id and use it with iron-router

后端 未结 2 1018
旧时难觅i
旧时难觅i 2021-02-10 18:55

i have a simple post route that looks for the post _id. The problem is that the pathFor helper creates a path like this:

ObjectID(\"52         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-02-10 19:11

    You need to change the pathFor 'post' to pass the hex representation of the ObjectId 52e16453431fc2fba4b6d6a8 instead of ObjectId('52e16453431fc2fba4b6d6a8')

    Try something like this pathFor 'post' _id=this._id.toHexString

    Once you are passing the hex string, you can use this in your router

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

提交回复
热议问题