【问题标题】:Not able to understand meteor specific syntax无法理解流星特定的语法
【发布时间】:2020-01-14 01:19:13
【问题描述】:

我正在阅读有关 Meteor 发布和订阅的信息,在那里我遇到了一个小代码 sn-p。虽然,我理解了文章的概念,但无法理解 sn-p 的代码语法。请帮帮我?

Meteor.publish('lists.public', function() {
  return Lists.find({
    userId: {$exists: false}
  }, {
    fields: Lists.publicFields
  });
});

【问题讨论】:

  • 具体哪一部分不清楚?
  • find方法里面的部分
  • 我没有看到特定于流星的代码本身。他在进行正常的查找,然后将他想要返回的字段列入白名单。请参考前面提到的文章,您会发现他正在将Lists.publicFields 设置为某个对象。
  • 你指的代码其实是Mongo代码,不是Meteor。

标签: javascript node.js meteor


【解决方案1】:

这是带有解释的代码。这有帮助吗?

// publish the result of this function to the client under the name 'lists.public'
Meteor.publish('lists.public', function() {  

  // Find in the Lists collection..
  return Lists.find({
    // ..all documents there the field userId does *not* exist.
    userId: {$exists: false}
  }, {
    // From the found records, only return the fields listed in Lists.publicFields.
    fields: Lists.publicFields
  });
});

您可能还想在某个地方console.log(Lists.publicFields),以防您不确定那里有什么。这不是特定于流星的,我不知道那里设置了什么。可能由您正在使用的软件包完成。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    相关资源
    最近更新 更多