【发布时间】:2016-06-03 21:22:12
【问题描述】:
目前,我的收藏有助手(使用 dburles:collection-helpers)。
例如,在我的 Teams 集合中,我定义了以下帮助程序。我在客户端使用这个助手:
getUnlockedProblems: function() {
return Problems.find({requirements: {$not: {$elemMatch: {$nin: this.getSolvedIds()}}}});
},
在我的 Publications.js 中,我有一个发布来发布团队已解决的问题,它基本上使用相同的查询,除了过滤掉 grader 字段:
return Problems.find({requirements: {$not: {$elemMatch: {$nin: team.getSolvedIds()}}}}, {fields: {grader: 0}});
有什么办法可以代替return team.getUnlockedProblems().project({fields: {grader: 0}}) 吗?所以我可以重复使用查询
【问题讨论】:
-
将
options参数添加到getUnlockedProblems是可接受的解决方案吗? -
@DavidWeldon 我想这行得通。不知道为什么我没有想到这样做!谢谢
-
太棒了。为了完整起见,我回答了我的评论。