您好我收集了以下文件
{
"_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 "
}
}
我的地图缩减代码在下面给出
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"}
})
当我运行此代码mongoshell时,它显示以下错误 “JavaScript执行失败:map reduce failed:{ “errmsg”:“异常:JavaScript执行失败:ReferenceError:tulpn未定义在'.netstat -tulpn;'(第5行)附近”, “code”:16722, “好的”:0 }
任何人都可以告诉我为什么mongo map减少不能用于包含两个单词空格的键吗?谁知道如何解决这个问题?
答案 0 :(得分:1)
尝试使用values[i].commands['netstat -tulpn']
代替values[i].commands.netstat -tulpn
。