admin管理员组文章数量:1313319
I have a collection in Meteor.js with properties which include a timestamp. For example:
Posts.insert({
category: 'type1',
text: 'hello world',
time: new Date(2012, 2, 14, 15, 25),
});
I know I can filter the Collection by matching a parameter, e.g.
Meteor.subscribe('posts', 'type1');
Meteor.publish('posts', function(category) {
return Posts.find({category: category});
});
However, I want to also be able to filter in more advanced ways: 1) by the "time" field, e.g. all posts in between Jan 1, 2012 and Jan 1, 2013. 2) by searching for all posts which have some word, e.g. "world" in the "text" field.
What is the correct way to do this?
I have a collection in Meteor.js with properties which include a timestamp. For example:
Posts.insert({
category: 'type1',
text: 'hello world',
time: new Date(2012, 2, 14, 15, 25),
});
I know I can filter the Collection by matching a parameter, e.g.
Meteor.subscribe('posts', 'type1');
Meteor.publish('posts', function(category) {
return Posts.find({category: category});
});
However, I want to also be able to filter in more advanced ways: 1) by the "time" field, e.g. all posts in between Jan 1, 2012 and Jan 1, 2013. 2) by searching for all posts which have some word, e.g. "world" in the "text" field.
What is the correct way to do this?
Share Improve this question asked Feb 25, 2014 at 23:46 genekogangenekogan 7212 gold badges10 silver badges22 bronze badges 01 Answer
Reset to default 9You can just bine selectors like so:
Posts.find({
category: category,
time: {$gte: date1, $lte: date2},
text: new RegExp(searchTerm)
});
本文标签: javascriptFiltering a collection in Meteorjs by a date range or word filterStack Overflow
版权声明:本文标题:javascript - Filtering a collection in Meteor.js by a date range or word filter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741926407a2405316.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论