Mongo用户定义的函数和Map Reduce [英] Mongo User Defined Functions and Map Reduce

查看:98
本文介绍了Mongo用户定义的函数和Map Reduce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mongo中是否有一种创建用户定义的Javascript函数的方法.我想在其他MR函数中使用一些客户端的Map/Reduce函数.

Is there a way in mongo to create user-defined Javascript functions. I have several Map/Reduce functions on the client side that i would like to use within other MR functions.

例如,几个MR函数计算各种平均值.我希望能够像这样使用它们:

For example, several MR functions calculate all sorts of averages. I want to be able to use them like so :

function reduce(k,v)
{
    if (val > myDatabaseAverage())
    // ..do something
}

推荐答案

使用db.system.js.save({_id:"myDatabaseAverage",value:function(){//..do something}}));

Use db.system.js.save( { _id : "myDatabaseAverage" , value : function(){ // ..do something } } );

这会将JS函数存储在服务器上,并且从那以后m/r可以对其进行访问.

That will store the JS function on the server and can be accessed by m/r from that point on.

有关更多示例,请参见: https://github.com/mongodb/mongo/blob/master/jstests/storefunc.js

For further examples see : https://github.com/mongodb/mongo/blob/master/jstests/storefunc.js

这篇关于Mongo用户定义的函数和Map Reduce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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