I'm creating a Meteor learning project. There is a collection in it, its documents have a property named keywords which is an array of strings. I have a second array of strings. I want to filter the collection that way, that it returned only those documents which keywords array intersect with that second array, i.e. both arrays have one or several same elements. Is it possible?
Yes, a query would be:
var searchKeywords = ['a','b','c','d']
MyCollection = new Mongo.Collection('mycollection');
MyCollection.insert({
keywords: ['x','y','a','b']
});
// returns some ID
MyCollection.findOne({
keywords: { $in: searchKeywords }
})._id
// returns the same ID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With