【问题标题】:Mongo's elemMatch with meteor publish compositeMongo 的 elemMatch 与流星发布复合
【发布时间】:2015-07-24 18:33:51
【问题描述】:

我有一个类似于以下示例的 Mongo 集合,我正在使用流星发布复合,https://atmospherejs.com/reywood/publish-composite 将文档发布到客户端。我知道使用 Mongo 我可以执行以下操作来返回作者数组中的特定项目。

db.books.find({"authors.authorSlug": "author-1}, {authors: {$elemMatch: { authorSlug: "author-1"}});

当我尝试使用meteor-publish-composite 实现相同的目标时,这似乎不起作用,因为它返回整个作者的数组,我的代码如下。

Books.find({"authors.authorSlug": slug}, {authors: {$elemMatch:{authorSlug: slug}}});

这甚至可以通过发布复合来实现吗?

{
    "title" : "Book1",
    "authors" : [
        {
            "name" : "Author 1",
            "authorSlug": "author-1"
        },
        {
            "name" : "Author 2",
            "slug" : "author-2"
        },
    ],
    "slug" : "book1"
}

【问题讨论】:

    标签: meteor mongodb-query meteorite


    【解决方案1】:

    仅当您尝试将 2 个或更多相关集合加入到单个反应式订阅中时,您才使用发布复合。你只需要一个标准的发布/订阅你的收藏-你说你有工作代码,所以我看不出你的问题是什么!或者,除了周围的其他数据之外,您还想获取您的图书数据吗?

    【讨论】:

      猜你喜欢
      • 2017-05-12
      • 2023-03-15
      • 2016-01-11
      • 2015-02-23
      • 2013-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      相关资源
      最近更新 更多