javascript - 如何返回两个字段,对 meteor 中的帖子有不同的限制

标签 javascript mongodb collections meteor find

我有一个名为 Posts 的集合,我正在尝试输出 {{url}} 但将其限制为仅第一个,并尝试输出 {{thumbs}} 但所有这些。到目前为止,唯一发生的事情是所有的 {{thumbs}} 都显示出来,因为它是最后一个,我如何让主题都工作?

return Posts.find({}, {fields: { url: 1}, limit:1}), Posts.find({}, {fields: { thumb: 1}});

编辑 整个模板助手

Template.motionPictures.helpers({
  posts: function() {

    Posts.find({}, {fields: {thumb: 1, url: 1}}).map(function(post, index) {
  if (index === 0) {
    return post;
  } else {
    delete post.thumb;
    return post;
  }
});
}
});

最佳答案

这有效吗?

Posts.find({}, {fields: {thumb: 1, url: 1}}).map(function(post, index) {
  if (index === 0) {
    return post;
  } else {
    delete post.thumb;
    return post;
  }
});

它会查找具有这两个字段的所有帖子,并且仅当该帖子不是第一个帖子时才删除缩略图。

关于javascript - 如何返回两个字段,对 meteor 中的帖子有不同的限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24091297/

相关文章:

java - 使用 Guava 将多个 Collections<A> 合并到一个 Collection<B> 中的单个 Collection<A>

JavaScript 输出到文件

javascript - MomentJS 将 'a day ago' 更改为 '1d'

javascript - 如何在 Node.js 中使用 MongoDB 的 populate 方法?

node.js - Mongodb-类型错误: ReplSetServers is not a function

node.js - 从模型创建对象时。该对象未定义

c# - 我可以有条件地使用 LINQ 创建 IEnumerable 吗?

javascript - JQuery tablesorter,<table> in <table>(嵌套表)

Javascript RegExp解析IRC颜色代码

java - 对象的迭代器[]