1

我正在我的 Node.js + Express.js 服务器上执行 MapReduce。

我使用 Mongoose 作为 ODM,我需要将一个键值数组命名_affinitiesmap函数全局范围。为此,我目前正在o.scope对象内部传递数组:

var o = {}; // Object sent to Mongoose as options

// Scope to pass affinities
o.scope = {
    affs : _affinities,
    test : 'test'
}

但是,在使用这些值时o.map,它说affs是一个空数组。但是,如果我尝试记录test,它会显示正确的值。

// Note: this is just a test, I don't need to pass affs & test as the key.
o.map = function() {
    emit({ 
       a : affs, 
       test : test,
       id : this._id 
    }, this.score);
}

我只有一个 finalize 函数(用于测试),没有reduce一个。

o.finalize = function (k, v) 
{
    return v;
}

MyModel.mapReduce(o, callback);

难道我做错了什么?MongoDB 传递数组不支持?

4

0 回答 0