目前在meteor.js中,我试图弄清楚如何返回包含特定值的字段的所有集合:
Posts.insert({
tags: ['test', 'test1', 'test2'],
categories: ['test', 'planning'],
article: {
title: 'Lorem ipsum dollar sum import',
content: 'Lorem balck solo su, bella hun sillo.',
author: 'test'
},
comments: [{title: 'test', 'content': 'hello world'},],
});
因此,例如,在按类别过滤帖子的上下文中,如何返回类别数组中包含与“测试”或“计划”匹配的字符串的所有集合,并排除数组中不包含该字符串的集合?
这是我一直在开发的一个简单的博客应用程序,如果有更有效的方法来存储帖子和相关信息,请让我知道世界很棒。
最佳答案
您可以使用$in运算符(operator)。例如:
Posts.find({categories: {$in: ['test', 'planning']}});
将查找 categories
至少有一个元素与 'test'
或 'planning'
匹配的所有帖子。
关于javascript - Meteor.js 按字段中的值过滤集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29022105/