简体   繁体   English

Meteor.js按字段中的值过滤集合

[英]Meteor.js filter collections by value in field

Currently in meteor.js im trying to figure out how to return all collections with a field containing a particular value: 当前在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'},], }); 

So, for instance in the context of filtering posts by category how can I return all the collections with the categories array containing a string matching 'test' or 'planning' and exclude those that don't contain that string in the array? 因此,例如,在按类别过滤帖子的情况下,如何返回所有类别数组包含具有匹配“ test”或“ planning”的字符串的类别集合,并排除那些在数组中不包含该字符串的集合?

This is for a simple blog app I have been working on, also if there is a more efficient way of storing posts and associated information please let me know that world be awesome. 这是我一直在使用的简单博客应用程序,如果还有更有效的存储帖子和相关信息的方法,请告诉我,世界真棒。

You can use the $in operator. 您可以使用$ in运算符。 For example: 例如:

Posts.find({categories: {$in: ['test', 'planning']}});

Would find all posts where categories has at least one element matching either 'test' or 'planning' . 将查找所有categories至少具有一个与'test''planning'匹配的元素的帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM