0

I am using meteor.js to write a large modular app. Inside my app, I have a collection named "Courses". The Schema of a object inside of the course collection looks like:

_id: MongoId
title: String
intro: String
content: Object
settings: Object
    secret: Object
    nonSecrets: Object
members: [Object]
    userId: MongoId
    wantsMail: Boolean
    gotMemberAt: Date

I have several Publications:

# Publish an overview of all courses, I am Member at
Meteor.publish 'myCourses', ->
     return Courses.find(
           {members:{$elemMatch:{userId: @userId}}},
           {fields:{title:1, intro:1, 'settings.nonsecret':1, 'members.$':1}}
     )

# Single Course Detail
Meteor.publish 'singleCourse', (id) ->
    return Courses.find(
        id, 
        {fields: {title:1, intro:1, content:1, 'settings.nonSecret':1}}
    )

# Admin Information of course
Meteor.publish 'singleCourseAdamin', (id) ->
    return Courses.find(
        id, 
        {fields: {title:1, settings:1, members:1}}
    )

My problem is now, that when I subscribe to all three publications, I don't get other members than those of the myCourses Publication.

Is there any good text about how publishing and subscribing to subsets of the same document work in actual meteor versions and what I need to check for if I want to make it work?

Or is there a package that make it easier to restrict the access to fields for each user?

4

1 回答 1

0

这是一个已知问题。我最近在常见错误中添加了一个关于它的部分(请参阅“合并框”)。虽然有一些复杂的解决方法,但您最好的选择是:

  1. 重新组织您的数据,以便不需要发布子字段。
  2. myCourses一次只使用一个需要特定子字段的发布者(在这种情况下,也许您可​​以在管理员发布者处于活动状态时关闭发布者)。这可能很难保证。
  3. 只需发布更多数据(整个领域)。显然,在某些情况下这可能行不通——尤其是在存在安全问题的情况下。

另请注意,settings当第一个和最后一个发布者都处于活动状态时,您应该在该字段上遇到相同的问题。

于 2015-11-16T03:13:43.063 回答