Eva*_*nis 7 arrays filtering intersection mongodb meteor
我正在创建一个流星学习项目.其中有一个集合,其文档有一个名为keywords的属性,这是一个字符串数组.我有第二个字符串数组.我想以这种方式过滤集合,它只返回关键字数组与第二个数组相交的那些文档,即两个数组都有一个或几个相同的元素.可能吗?
Ser*_*soy 18
是的,查询将是:
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
Run Code Online (Sandbox Code Playgroud)