目前在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'},],
});
因此,例如在按类别过滤帖子的上下文中,如何返回包含与“test”或“planning”匹配的字符串的categories数组的所有集合,并排除那些在数组中不包含该字符串的集合?
这是我一直在努力的一个简单的博客应用程序,如果有更有效的方式来存储帖子和相关信息,请让我知道这个世界真棒。
答案 0 :(得分:3)
您可以使用$in运算符。例如:
Posts.find({categories: {$in: ['test', 'planning']}});
会找到categories
至少有一个元素与'test'
或'planning'
匹配的所有帖子。