Mongo User Defined Functions and Map Reduce

前端 未结 2 1133
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 19:37

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 function

相关标签:
2条回答
  • 2021-01-14 20:04

    Use

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

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

    For further examples see : mongo/jstests/core/mr_stored.js

    0 讨论(0)
  • 2021-01-14 20:20

    As mentioned by @Remon van Vliet,

    You will have to use,

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

    to save your function first,

    and then you need to call,

    db.loadServerScripts();
    

    before you execute your function.

    0 讨论(0)
提交回复
热议问题