有人可以指出发布功能是否需要monogdb的forEach
操作,流星' this.added或Meteor的observe功能。
当前的发布功能有效,但不确定这是否是我主要担心的反应。
对于添加到博客集合中的每个新文档,forEach函数是否都会运行?
user1 _id
嵌入在Blogs
集合中的多个文档中,如下所示:
creator: user1's_id
在此博客文档中,还有一个用于其他用户'协作者的字段:
creator: user1's_id
collaborator: anotherUser_id
User1可能是百博客文档的创建者,但协作者对于每个博客文档都将是不同的。
我想为creator
的用户创建Meteor.publish函数并返回以下两个游标
creator
所有Meteor.users()都是collaborator
Meteor.publish('creatorBlogContext', function() {
var user = Meteor.users.findOne(this.userId)
if (user && user.profile.userType === 'creator') {
var blogsCursor = Blogs.find({'creator': user._id}); //returns all blog docs the user has created.
var userIdsArray = []
Blogs.find({'creator': user._id}).forEach(function(doc) {
userIdsArray.push(doc.collaborator)
})
var usersCursor = Meteor.users.find({_id: {$in: userIdsArray}})
return [blogsCursor, usersCursor];
}
});
当新的Blog文档因此forEach函数推出协作者的Meteor.user时,上述函数是否会被动地重新运行?
注意:我不希望使用铁路由器并在发布功能中执行findOne,具体取决于创建者正在查看的博客。我希望以核心流星方式做到这一点,所以请不要包装建议。
谢谢,如果我不清楚,请询问进一步的信息。