Mongo 用户定义函数和 Map Reduce [英] Mongo User Defined Functions and Map Reduce
本文介绍了Mongo 用户定义函数和 Map Reduce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 mongo 中有没有办法创建用户定义的 Javascript 函数.我在客户端有几个 Map/Reduce 函数,我想在其他 MR 函数中使用它们.
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
} } );
这会将 JS 函数存储在服务器上,并且从那时起 m/r 可以访问.
That will store the JS function on the server and can be accessed by m/r from that point on.
更多示例参见:mongo/jstests/core/mr_stored.js
这篇关于Mongo 用户定义函数和 Map Reduce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文