简体   繁体   English

如何基于数组值的值发布集合

[英]How to publish a collection based on a value of an array value

I have the following data structure in a Meteor app, I would like to create a publication based on the "modelo" value. 我在Meteor应用程序中具有以下数据结构,我想基于“ modelo”值创建发布。

{
  "_id": "BAnLur25298ytvMdT",
  "numero": "97",
  "lienzos": 100,
  "fechaCorte": "2016-03-29T00:00:00.000Z",
  "modelos": [
    {
      "modelo": "95",
      "distribucion": 100
    },
    {
      "modelo": "96",
      "distribucion": 100
    }
  ],
  "tela": "Jackard"
}

For example : 例如 :

Meteor.publish('ModelosCorte', function(id) {
  return CortesGeneral.find({
    modelos: id
  });
});

But I want to publish for example all CortesGeneral that have a "modelo": "96" as a value 但是我想发布例如所有具有“ modelo”:“ 96”作为值的CortesGeneral。

You need to use dot notation to specify that you want to search for 'modelos.modelo' . 您需要使用点表示法来指定要搜索的'modelos.modelo' Give this a try: 试试看:

Meteor.publish('ModelosCorte', function (id) {
  check(id, String);
  return CortesGeneral.find({ 'modelos.modelo': id });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM