Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 流星铁:获取ID的路由器问题_Meteor_Iron Router - Fatal编程技术网

Meteor 流星铁:获取ID的路由器问题

Meteor 流星铁:获取ID的路由器问题,meteor,iron-router,Meteor,Iron Router,有人能解释为什么我得到的是ObjectID的全部值而不是干净的ID吗 这就是我得到的: 以及HTML输出: <a href="/summary/ObjectID(%2254ab87a24c38814aa128da7b%22)">My Post</a> 列表页面模板:模板/posts/post_dashboard.html {{#each posts}} <tr> <td> <p><

有人能解释为什么我得到的是ObjectID的全部值而不是干净的ID吗

这就是我得到的:

以及HTML输出:

<a href="/summary/ObjectID(%2254ab87a24c38814aa128da7b%22)">My Post</a>
列表页面模板:模板/posts/post_dashboard.html

{{#each posts}}
    <tr>
        <td>
            <p><a href="{{pathFor 'postSummary'}}">{{title}}</a></p>
            <p><small>Created at {{createdAt}}</small></p>
        </td>
        ...
    </tr>
{{/each}}
<template name="postSummary">
    {{> postHeader}}

    <h3>{{title}}</h3>
</template>
这是我安装的软件包,以防万一

meteor-platform
autopublish
insecure
matthew:foundation5-sass
iron:router
jquery
useraccounts:core
useraccounts:foundation
accounts-password
accounts-facebook
accounts-google
accounts-ui-unstyled
aldeed:autoform
aldeed:collection2
forwarder:autoform-wizard
fortawesome:fontawesome

从控制台查询
Posts
集合时,返回文档中的
\u id
是字符串文本还是ObjectId对象

假设是后者,这就是为什么会发生这种情况,如果是这样,可能是因为您在Mongo shell中使用
insert
填充了集合(或者从现有MongoDB还原)。默认情况下,Meteor insert在未指定id时使用字符串作为自动添加的id,而Mongo使用ObjectID


希望这能有所帮助,但如果我完全走错了方向,请告诉我

从控制台查询
Posts
集合时,返回文档中的
\u id
是字符串文本还是ObjectId对象

假设是后者,这就是为什么会发生这种情况,如果是这样,可能是因为您在Mongo shell中使用
insert
填充了集合(或者从现有MongoDB还原)。默认情况下,Meteor insert在未指定id时使用字符串作为自动添加的id,而Mongo使用ObjectID



希望这能有所帮助,但如果我完全走错了方向,请告诉我

Mongo ObjectID有一个属性:
\u str
它包括ID的字符串表示。

Mongo ObjectID有一个属性:
\u str
它包括ID的字符串表示。

是的。我已经通过mongo shell插入了数据。无论如何,我只是做了一次流星重置,尝试通过浏览器控制台和脚本插入数据。但是这两个返回都
insert失败:错误:Sample是必需的
。这是因为它位于您用Collection2定义的架构中,而不是您试图插入的项吗?我不明白您的意思。这是什么集合2?您在上面列表中提供的包之一。是的,准确地说-它不允许您在Meteor中插入任何不符合模式的内容。显然,当你通过shell直接进入MongoDB时,这是无关紧要的。我已经通过mongo shell插入了数据。无论如何,我只是做了一次流星重置,尝试通过浏览器控制台和脚本插入数据。但是这两个返回都
insert失败:错误:Sample是必需的
。这是因为它位于您用Collection2定义的架构中,而不是您试图插入的项吗?我不明白您的意思。这是什么集合2?您在上面列表中提供的包之一。是的,准确地说-它不允许您在Meteor中插入任何不符合模式的内容。显然,当你通过shell直接进入MongoDB时,这是无关紧要的。。也许我只是愚蠢。但是
this.params.\u id.\u str
仍然返回完整的ObjectId.Hmm。你的帖子集很奇怪;P如何将文档插入其中?好的-我现在查看了上面的评论,现在对我来说更清楚了:)当您将插入文档而不是使用mongo shell时,它应该可以为您工作。嗯。。也许我只是愚蠢。但是
this.params.\u id.\u str
仍然返回完整的ObjectId.Hmm。你的帖子集很奇怪;P您如何将文档插入其中?好的-我现在查看了上面的注释,现在对我来说更清楚了:)当您将插入不使用mongo shell的文档时,应该可以正常工作。
Template.dashboard.helpers({
    posts: function () {
        return Post.find({});
    }
});
meteor-platform
autopublish
insecure
matthew:foundation5-sass
iron:router
jquery
useraccounts:core
useraccounts:foundation
accounts-password
accounts-facebook
accounts-google
accounts-ui-unstyled
aldeed:autoform
aldeed:collection2
forwarder:autoform-wizard
fortawesome:fontawesome