在MongoDB下的Java驱动程序Mapreduce命令范围;将功能添加到范围 [英] Under MongoDB java driver Mapreduce command scope; add functions to Scope

查看:75
本文介绍了在MongoDB下的Java驱动程序Mapreduce命令范围;将功能添加到范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它们是通过Java驱动程序执行MongoDB映射减少作业的一种方法,您可以在Java驱动程序中创建包含函数的作用域DBObject.

Is their a way to Execute a MongoDB map reduce job through the java driver in which you create a scope DBObject that contains functions.

我可以在javascript中执行我的map reduce配置,其中传入的范围包含实用程序功能,但是我不知道如何使用Java驱动程序来完成此操作.

I can execute my map reduce configuration in javascript where the passed in scope contains utility functions, but I can't figure out how to do this with the java driver.

我使用mapReduceCommand的

I setup the scope using mapReduceCommand's

c.addExtraOption("scope",new BasicDBObject().append('average',function(){ return false;}));

但是我无法让映射器/归约器识别范围组件例如".平均功能.如果我使用引号,则map reduce上下文会认为它是一个String,但如果不是,则似乎无法对范围组件进行解析.

However I can't get the mappers/reducers to recognize the scope component 'e.g.' average as a function. If I use quotes, the map reduce context thinks its a String, but if not, I can't seem to make the scope component parse.

如何通过Java驱动程序在范围组件中获得功能?

How does one get a function in the scope component through the java driver?

感谢Ren的回答,这是一个Spring bean配置,用于使用功能为mongodb java驱动程序设置作用域.

Thanks to Ren's answer, Here is a spring bean configuration to set up a scope for the mongodb java driver with a function.

    <util:map id="mrScope" 
              key-type="java.lang.String" 
              value-type="java.lang.Object">
    <entry key="buckets"><bean class="com.mongodb.util.JSON" factory-method="parse"><constructor-arg value="[0,10,15,20,25,30,35,40,45,50,55,60,65]"/></bean></entry>
    <entry key="average">
        <bean class="org.bson.types.CodeWScope">
            <constructor-arg value="function () {var s = 0;for (var i = 0; i &gt; arguments.length; i++) s += arguments[i];return s / arguments.length;}"/>
            <constructor-arg><bean class="org.bson.BasicBSONObject"/></constructor-arg>
        </bean>
    </entry>

推荐答案

服务器代码自动将地图转换并归约为Javascript函数,但作用域不是这样.要在scope选项中传递函数,可以改为执行以下操作:

The server code automatically converts the map and reduce into Javascript function, but not so with scope. To pass a function in the scope option, you can do this instead:

c.addExtraOption("scope", new BasicBSONObject("average",
  new CodeWScope("function(){ return false;}", new BasicBSONObject())));

这篇关于在MongoDB下的Java驱动程序Mapreduce命令范围;将功能添加到范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆