One publication is hiding nested fields from another publication

后端 未结 2 1770
抹茶落季
抹茶落季 2020-12-07 05:06

Given two publications for the same collection named Foo. The fooList should only return specific fields but the fooDetail should return the whole document.

Server:<

相关标签:
2条回答
  • 2020-12-07 05:43

    Your pub/sub looks good. My guess is that you haven't added reactivity to the fooDetail sub. Do me a favor:

    1. put both subs in a waitOn on iron router, passing in a static value to fooDetail.
    2. Verify in minimongo that the other fields are there for the static id.
    3. Wrap the sub in a Template.Instance().autorun
    0 讨论(0)
  • 2020-12-07 05:54

    This isn't a bug, it's a known limitation of the meteor's MergeBox. It's one of those confusing problems that bites most meteor developers once.

    From the docs:

    If more than one subscription sends conflicting values for a field (same collection name, document ID, and field name), then the value on the client will be one of the published values, chosen arbitrarily.

    You can see this post for possible workarounds. In your example, you could modify your publish to look like:

    Meteor.publish 'fooList', ->
      Foo.find {}, fields: foo: 1, bar: 1
    

    That would publish all of the top-level bar field which avoids the conflict but may not be acceptable in your particular use case.

    0 讨论(0)
提交回复
热议问题