2013-07-15 26 views
10

私は...それは正常に動作しますが、私は「機能」セクションで作成した機能にアクセスする方法を理解できないのMongoDBクライアントを使用するRobomongo、カスタム関数の使い方は?

http://robomongo.org/

を「Robomongo」をしようとしていますMapReduceの機能をテストしたいので、私は(マップを作成しました)と()関数を削減するが、私は自分の殻に書くとき:

db.<name_of_collection>.mapReduce(map, reduce, {out: {inline: 1}}); 

Robomongoは私に次のエラーを与える:

ReferenceError: map is not defined (shell):1 

私もこのように試してみた:

db.<collection_name>.mapReduce(db.system.js.map, db.system.js.reduce, {out: {inline: 1}}); 

しかし、再び、何かが間違っているようだ...

uncaught exception: map reduce failed:{ 
    "errmsg" : "exception: JavaScript execution failed: ReferenceError: learn is not defined", 
    "code" : 16722, 
    "ok" : 0 
} 

答えて

19

あなたはいくつかの方法で保存された機能にアクセスすることができます

1)

db.collection.mapReduce(
    "function() { return map(); }", 
    "function(key, values) { return reduce(key, values); }", 
    {out: {inline: 1}}); 

2)私たちは今の機能を使用している

db.collection.mapReduce(
    function() { return map(); }, 
    function(key, values) { return reduce(key, values); }, 
    {out: {inline: 1}}); 

注、1のようではない文字列)

3)

あなたは上記のMongoDB 2.1以上を使用している場合は、あなたはできる:

db.loadServerScripts(); 
db.collection.mapReduce(
    map, 
    reduce, 
    {out: {inline: 1}});  

詳細についてはこちら http://docs.mongodb.org/manual/tutorial/store-javascript-function-on-server/

RobomongoはMongoDBシェルで使用されているのと同じエンジンを使用します。あなたの質問は、Robomongoではなく、MongoDBに関するものです。シェルコマンドのテキストボックスにRoboMongoを使用して関数を作成した後

9

、 次のように入力します

db.loadServerScripts(); 
myFunctionName(); 

とツールバー

Executeボタンをクリックしてください