Mongoose mapreduce:使用array.some映射函数

Mongoose mapreduce:使用array.some映射函数,mapreduce,mongoose,Mapreduce,Mongoose,此Javascript在my map函数之外运行良好: var cribs = ["list","tree"]; if ( cribs.some(function(i){return (new RegExp(i,'gi')).test("a long list of words");}) ) { console.log('match'); } (它只是用数组中的值搜索字符串) 虽然在“我的地图”功能中使用它不起作用: var o = {}; o.map = function () {

此Javascript在my map函数之外运行良好:

var cribs = ["list","tree"];

if ( cribs.some(function(i){return (new RegExp(i,'gi')).test("a long list of words");}) ) {
 console.log('match');
}
(它只是用数组中的值搜索字符串)

虽然在“我的地图”功能中使用它不起作用:

var o = {};
o.map = function () { 
    if ( cribs.some(function(i){return (new RegExp(i,'gi')).test(this.name);}) ) {
        emit(this, 1) ;
    }
}
o.out = { replace: 'results' }
o.verbose = true;
textEntriesModel.mapReduce(o, function (err, model, stats) {
    model.find(function(err, data){
        console.log(data);
    });
})
它不发射任何东西,所以我有一个空的结果集。没有错误

如果我不使用array.some,而只使用普通正则表达式,那么它可以正常工作:

o.map = function () { 
    if(this.name.match(new RegExp(/list/gi))) {
        emit(this, 1) ;
    }
}
所以我的问题是,为什么上面的array.some函数不能在map函数中工作

我有一长串需要匹配的单词,所以我真的不想为它们单独编写正则表达式,因为上面的方法应该适用


下面是我试图在map函数中使用的函数的一部分:

您需要通过将
cribs
添加到
scope
选项,使
map
函数可用:

var cribs=[“列表”、“树”];
var o={};
o、 map=函数(){
if(cribs.some(函数(i){return(newregexp(i,'gi'))).test(this.name);})){
发射(本,1);
}
}
o、 out={replace:'results'};
o、 范围={cribs:cribs};
o、 冗长=真实;
textEntriesModel.mapReduce(o,函数(err,model,stats){
model.find(函数(错误、数据){
控制台日志(数据);
});
});