Error in MapReduce command with MongoDB Java API -


i'm testing mongodb java api , wanted mapreduce. implemented follow :

string map = "function() { " +     "emit(this.ts, this.1_bid);}";  string reduce = "function(key, values) {" +     "return array.sum(values);}";  mapreducecommand cmd = new mapreducecommand(collection, map, reduce, null, mapreducecommand.outputtype.inline, null); mapreduceoutput out = collection.mapreduce(cmd);  (dbobject o : out.results()) {     system.out.println(o.tostring()); } 

but when execute have following exception stack :

[tick_engine] 16:51:53.600 error [mongotickdatareader] failed read data mongodb com.mongodb.commandfailureexception: { "serverused" : "/127.0.0.1:27017" , "errmsg" : "exception: syntaxerror: unexpected token illegal" , "code" : 16722 , "ok" : 0.0}     @ com.mongodb.commandresult.getexception(commandresult.java:71) ~[mongo-2.11.1.jar:na]     @ com.mongodb.commandresult.throwonerror(commandresult.java:110) ~[mongo-2.11.1.jar:na]     @ com.mongodb.dbcollection.mapreduce(dbcollection.java:1265) ~[mongo-2.11.1.jar:na]     @ com.smarttrade.tickengine.in.mongotickdatareader.mapreduce(mongotickdatareader.java:321) ~[classes/:na]     @ com.smarttrade.tickengine.in.mongotickdatareader.readdata(mongotickdatareader.java:157) ~[classes/:na]     @ com.smarttrade.tick.engine.tickengine.onmarketdatarequest(tickengine.java:203) [classes/:na]     @ com.smarttrade.tick.sttp.tickmarketdatarequestcommand.execute(tickmarketdatarequestcommand.java:62) [classes/:na]     @ com.smarttrade.st.commands.command.process(command.java:140) [src/:na]     @ com.smarttrade.st.server.sttpinvoker$1.process(sttpinvoker.java:385) [src/:na]     @ com.smarttrade.st.server.sttpinvoker$1.process(sttpinvoker.java:1) [src/:na]     @ com.smarttrade.util.concurrent.queue.multisessionsblockingqueue$simplesession.run(multisessionsblockingqueue.java:122) [src/:na]     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) [na:1.7.0_51]     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) [na:1.7.0_51]     @ java.lang.thread.run(thread.java:744) [na:1.7.0_51] 

the problem seems attribute name have defined - 1_bid

i created sample documents test map-reduce -

{ "_id" : objectid("533ef7d0e1687dd644410d88"), "ts" : "tskey", "1_bid" : 200 } { "_id" : objectid("533ef7d3e1687dd644410d89"), "ts" : "tskey", "1_bid" : 300 } { "_id" : objectid("533ef7d5e1687dd644410d8a"), "ts" : "tskey", "1_bid" : 400 } { "_id" : objectid("533ef7dce1687dd644410d8b"), "ts" : "tskey2", "1_bid" : 800 } { "_id" : objectid("533ef7dfe1687dd644410d8c"), "ts" : "tskey2", "1_bid" : 300 } 

i ran following map-reduce command -

db.sample4.mapreduce(function() { emit(this.ts, this.1_bid);},function(key, values) {return array.sum(values);}) 

the error got syntaxerror: missing ) after argument list (shell):1

i realized, function, mapper executing, javascript function , in javascript, cannot have variable starts number. hence syntax error. created new set of documents -

{ "_id" : objectid("533eff29e1687dd644410d8d"), "ts" : "tskey", "bid_1" : 200 } { "_id" : objectid("533eff2de1687dd644410d8e"), "ts" : "tskey", "bid_1" : 300 } { "_id" : objectid("533eff34e1687dd644410d8f"), "ts" : "tskey", "bid_1" : 400 } { "_id" : objectid("533eff7fe1687dd644410d92"), "ts" : "tskey2", "bid_1" : 800 } { "_id" : objectid("533eff85e1687dd644410d93"), "ts" : "tskey2", "bid_1" : 300 } 

and modified mapper use "bid_1" , ran following command -

db.sample4.mapreduce(function() { emit(this.ts, this.bid_1);},function(key, values) {return array.sum(values);},"pivot") 

the output - { "result" : "pivot", "timemillis" : 61, "counts" : { "input" : 12, "emit" : 12, "reduce" : 2, "output" : 2 }, "ok" : 1, }

db.pivot.find() { "_id" : "tskey", "value" : 900 } { "_id" : "tskey2", "value" : 1100 } 

i tested in java using same program have pasted , changed attribute name "bid_1" , worked


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -