一个出版物隐藏了另一个出版物的嵌套字段 [英] One publication is hiding nested fields from another publication

查看:158
本文介绍了一个出版物隐藏了另一个出版物的嵌套字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于两个名为Foo的同一集合的出版物。 fooList应仅返回特定字段,但fooDetail应返回整个文档。

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

服务器:

Meteor.publish 'fooList', ->
    return Foo.find(
        {}
        { fields:
            foo: true
            'bar.bas': true
        })

Meteor.publish 'fooDetail', (foo_id) ->
    return Foo.find _id: foo_id

客户:

Meteor.subscribe 'fooList'
Meteor.subscribe 'fooDetail', some_id

我希望在订阅fooDetail时获得完整的foo。 但是bar(嵌套文档)中的所有字段都不可用,除了bar.bas字段。

I expected to get the complete foo when subscribing to fooDetail. But all the fields from 'bar' (the nested document) are not available, except the 'bar.bas' field.

这是一个错误或流星应该这样工作? (我目前在Meteor 1.0.3.2和铁路由器上)

Is this a bug or should meteor work this way? (I'm currently on Meteor 1.0.3.2 and Iron-Router)

推荐答案

这不是一个bug,它是一个<流星的 MergeBox 。这是困扰大多数流星开发者一次的令人困惑的问题之一。

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.

来自 docs


如果多个订阅发送字段的冲突值(相同的集合名称) ,文档ID和字段名称),然后客户端上的值将是任意选择的已发布值之一。

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.

这篇关于一个出版物隐藏了另一个出版物的嵌套字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆