Mongodb 如何在不使用简单模式的情况下关联Meteor中的Mongo集合

Mongodb 如何在不使用简单模式的情况下关联Meteor中的Mongo集合,mongodb,meteor,meteor-blaze,meteor-helper,Mongodb,Meteor,Meteor Blaze,Meteor Helper,我在做一个流星项目 第一步 我添加了帐户密码和帐户ui包,以便拥有用户集合和身份验证系统 步骤2 我已经创建了一个Mongo文档集合“Posts”,其中包含以下字段:_id、title、description和createdOn(日期) 步骤3 我创建了另一个Mongo文档集合“Comments”,其中包含以下字段:_id、comment、postedOn(“日期”)和createdBy(Meteor.user()。_id) 步骤4 我添加了iron路由器包并设置了一些路由。您可以查看博客列表并

我在做一个流星项目

第一步

我添加了帐户密码和帐户ui包,以便拥有用户集合和身份验证系统

步骤2

我已经创建了一个Mongo文档集合“Posts”,其中包含以下字段:_id、title、description和createdOn(日期)

步骤3

我创建了另一个Mongo文档集合“Comments”,其中包含以下字段:_id、comment、postedOn(“日期”)和createdBy(Meteor.user()。_id)

步骤4

我添加了iron路由器包并设置了一些路由。您可以查看博客列表并转到单篇文章详细信息页面。 我想给登录的用户提供发表评论的可能性 在单个注释上,而不使用aldeed简单模式包

以下是我的项目中的一些片段:

 Template.posts_list.helpers({
    posts:function(){
        return Posts.find({}, {sort: {createdOn: -1} });
    }
})
 Template.comments.helpers({
    comments:function(){
        return Comments.find({ ?????  Ho can I associate comments to a single post? });

    }
})

我想知道如何在这两个集合之间建立适当的关联。我只想显示与相关帖子相关的评论。到目前为止,所有的评论都毫无区别地出现在每个帖子上。有什么帮助吗?谢谢

您想在评论模式中添加帖子。然后,每当你提交评论时,获取相关帖子的_id,并将其发送到你插入评论的meteor方法。大概是这样的:

// In your template events:
'submitCommentForm': function( event, template ) {
    var postId = this._id; // Make sure your post data context of this form is set in a #each or #with.
    Meteor.call('addComment', event.target.comment, postId, ...) // Assuming your comment is in some sort of named input with comment as the name.
}