Reputation: 7840
Hi I had following document in collection
{
"_id" : ObjectId("5236b303e4b074ca9f4ed453")
"Commands":{
"netstat -tulpn":"Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2285/mysqld
tcp 0 0 0.0.0.0:63342 0.0.0.0:* LISTEN 3992/java
tcp 0 0 0.0.0.0:33359 0.0.0.0:* LISTEN 1913/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1794/rpcbind
tcp 0 0 0.0.0.0:3216 0.0.0.0:* LISTEN 3485/skype
tcp 0 0 0.0.0.0:28017 0.0.0.0:* LISTEN 3821/mongod
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2628/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2147/sshd
tcp 0 0 127.0.0.1:44567 0.0.0.0:* LISTEN 11436/GoogleTalkPlu
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1987/cupsd
tcp 0 0 127.0.0.1:6942 0.0.0.0:* LISTEN 3992/java
tcp 0 0 127.0.0.1:55777 0.0.0.0:* LISTEN 11436/GoogleTalkPlu
tcp 0 0 127.0.0.1:6311 0.0.0.0:* LISTEN 5088/Rserve
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 3821/mongod
tcp 0 0 127.0.0.1:9001 0.0.0.0:* LISTEN 2382/java
tcp 0 0 :::111 :::* LISTEN 1794/rpcbind
tcp 0 0 :::22 :::* LISTEN 2147/sshd
tcp 0 0 :::36441 :::* LISTEN 1913/rpc.statd
udp 0 0 0.0.0.0:111 0.0.0.0:* 1794/rpcbind
udp 0 0 127.0.0.1:39287 0.0.0.0:* 3485/skype
udp 0 0 0.0.0.0:631 0.0.0.0:* 1987/cupsd
udp 0 0 0.0.0.0:3216 0.0.0.0:* 3485/skype
udp 0 0 0.0.0.0:52777 0.0.0.0:* 1913/rpc.statd
udp 0 0 0.0.0.0:817 0.0.0.0:* 1913/rpc.statd
udp 0 0 192.168.122.1:53 0.0.0.0:* 2628/dnsmasq
udp 0 0 0.0.0.0:697 0.0.0.0:* 1794/rpcbind
udp 0 0 0.0.0.0:67 0.0.0.0:* 2628/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 18609/dhclient
udp 0 0 :::111 :::* 1794/rpcbind
udp 0 0 :::697 :::* 1794/rpcbind
udp 0 0 :::47419 :::* 1913/rpc.statd "
}
}
and my map reduce code was given below
var mapfunction = function(){
var key,values;
for (var i in this.Commands) {
key = {id:this._id};
values = {commands:this.Commands};
emit(key,values);
}
}
var reducefunction = function(key,values){
var reduced = {netstat:[]};
for(var i =0 ; i< values.length;i++){
reduced.netstat = values[i].commands.netstat -tulpn;
}
return reduced;
}
db.collectioname.mapReduce(mapfunction,reducefunction,{
out: {replace:"final"}
})
When I was run this code mongoshell it shows following error "JavaScript execution failed: map reduce failed:{ "errmsg" : "exception: JavaScript execution failed: ReferenceError: tulpn is not defined near '.netstat -tulpn; ' (line 5)", "code" : 16722, "ok" : 0 }
Can any one tell me why mongo map reduced not worked on key which contains spaces in two words? Any one knows how to solved this issues?
Upvotes: 0
Views: 182
Reputation: 143299
Try values[i].commands['netstat -tulpn']
instead of values[i].commands.netstat -tulpn
.
Upvotes: 1