【问题标题】:Pass parameters to MapReduce in Mongo and C#在 Mongo 和 C# 中将参数传递给 MapReduce
【发布时间】:2012-02-09 03:11:40
【问题描述】:

我有一个字典,我想将它作为 JS 传递给我的 Map Reduce 查询的 Map 部分。这是可能的,甚至是合适的事情吗?

【问题讨论】:

    标签: c# asp.net asp.net-mvc mongodb


    【解决方案1】:

    您可以使用 scope 选项将参数发送到 map/reduce/finalize 函数

    根据doc

    db.runCommand(
     { mapreduce : <collection>,
       map : <mapfunction>,
       reduce : <reducefunction>
       [, query : <query filter object>]
       [, sort : <sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces>]
       [, limit : <number of objects to return from collection>]
       [, out : <see output options below>]
       [, keeptemp: <true|false>]
       [, finalize : <finalizefunction>]
       [, scope : <object where fields go into javascript global scope >]
       [, jsMode : true]
       [, verbose : true]
     }
    );
    

    scope - 可以传入可以访问的变量 映射/减少/完成。

    查看here的用法

    摘自链接

       res = t.mapReduce( m , r , { out : "mr5_out" , scope : { xx : 1 } } );
    

    我对 c# 驱动程序没有太多经验,但是根据上面的示例,您可以将对象 jsonify 并将其分配给范围。这样就可以了

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多