gpt4 book ai didi

javascript - 一份出版物对另一份出版物隐藏嵌套字段

转载 作者:行者123 更新时间:2023-11-30 12:27:11 24 4
gpt4 key购买 nike

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

服务器:

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”字段除外。

这是一个错误还是 meteor 应该以这种方式工作? (我目前使用的是 Meteor 1.0.3.2 和 Iron-Router)

最佳答案

这不是错误,这是一个 known limitation meteor 的MergeBox .这是曾经困扰大多数 meteor 开发人员的那些令人困惑的问题之一。

来自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.

可以看到this post可能的解决方法。在您的示例中,您可以将您的发布修改为:

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

这将发布所有顶级 bar 字段,从而避免冲突,但在您的特定用例中可能 Not Acceptable 。

关于javascript - 一份出版物对另一份出版物隐藏嵌套字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28969223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com