jiwang1980 发表于 2012-04-28 12:21

【解决】MongoDB有木有童鞋用过

本帖最后由 jiwang1980 于 2012-05-02 10:51 编辑

有2个小问题,看了这个模块后没有找到答案
1.如何执行 show dbs 和 show collections这样的命令 这个已经知道了
2.mapreduce好像未执行代码如下
...
my $map= <<EOF;
function(){
var tmp=this.model+"SPLIT"+this.warning;
emit(tmp, {day:this.day,warning:this.warning,count:1})
}
EOF

my $reduce = <<EOF;
function(key, values) {
   var result = {count:0,day:0,warning:'no'};
   values.forEach(function(v) { result.count += v.count;
   result.day=v.day;
   result.warning=v.warning; });
   return result;
   }
EOF

my $cmd = Tie::IxHash->new("mapreduce" => "ibatis",
             "map" => $map,
             "reduce" => $reduce,
             'query'=>{'day'=>{'$in'=>["$date_tag"]}},
             'out'=>{'replace'=>'respl',db=>'passport'},
          );

my $res = $db->runCommand($cmd);
print Dumper $res;

myeverthing 发表于 2012-04-28 14:45

"好像未执行代码"??
是什么意思?没有任何输出信息吗?
还有你的mongodb的是哪个版本?如果是1.8以上,Output options必须有。

jiwang1980 发表于 2012-04-28 15:32

回复 2# myeverthing


感谢回复,用的
2.0.2
加了
'out'=>{'replace'=>'respl',db=>'passport'}
但是在对应的库里找不到结果

   

jiwang1980 发表于 2012-04-28 15:35

回复 2# myeverthing

group在运行后可以直接获取结果

而mapreduce
my $res = $db->runCommand($cmd);
的$res的结果
    $VAR1 = bless( {
               '_database' => bless( {
                                       '_connection' => bless( {
                                                                   'find_master' => 0,
                                                                   'query_timeout' => 30000,
                                                                   'db_name' => 'admin',
                                                                   'auto_reconnect' => 1,
                                                                   'w' => 1,
                                                                   '_servers' => {},
                                                                   'ts' => 0,
                                                                   'right_port' => 27017,
                                                                   'wtimeout' => 1000,
                                                                   'left_port' => 27017,
                                                                   'port' => 27017,
                                                                   'host' => '127.0.0.1',
                                                                   'max_bson_size' => 16777216,
                                                                   'timeout' => 20000,
                                                                   'auto_connect' => 1
                                                               }, 'MongoDB::Connection' ),
                                       'name' => 'passport'
                                       }, 'MongoDB::Database' ),
               'name' => 'runCommand'
               }, 'MongoDB::Collection' );

myeverthing 发表于 2012-04-28 17:45

对mongo也只是刚接触,水平有限~~~
所以mapreduce都是直接在mongo下执行看下结果,再确定perl怎么写~~
"passport",有这db吧~~我都是同一个db下,没跨过db写,不太清楚,
等高手。。

fayland 发表于 2012-04-29 10:29

你在collection 下 ->runCommand 了。你应该在 db 下 runCommand

Thanks

jiwang1980 发表于 2012-04-29 15:54

回复 5# myeverthing


兄台可否把代码贴上来看看。
另外passport的库就是调用 runCommand的库

3ks


   

jiwang1980 发表于 2012-04-29 16:00

fayland 发表于 2012-04-29 10:29 static/image/common/back.gif
你在collection 下 ->runCommand 了。你应该在 db 下 runCommand

Thanks

兄台哪里看到我是在collection下runCommand?
我实在db下{:2_166:}

jiwang1980 发表于 2012-05-02 10:51

今天跑了下代码,结果正确。再次感谢myeverthing,以及其他童鞋:D
页: [1]
查看完整版本: 【解决】MongoDB有木有童鞋用过