如何返回两个字段,在流星上有不同的限制

How to return two fields, with different limits on posts in meteor

本文关键字:流星 字段 返回 何返回 两个      更新时间:2023-09-26

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

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;
  }
});

查找包含两个字段的所有post,并且仅当该post不是第一个时才删除拇指