繁体   English   中英

mongodb mapreduce可以将发射保存到集合中吗?

[英]mongodb mapreduce can save emit into collection?

我创建了一个功能图,就是这个

var m = function() { 
  hashtags = {}
  for(var i in this.entities.hashtags) {
    hashtags[this.entities.hashtags[i].text] = 1
  };
  var valor = {numtweets: 1 ,  
    dic_hastag: hashtags};
    print("  value: " + tojson(valor));
  emit(this.place.country_code, valor)
};

我从一个名为tweets的集合开始,我的map函数的输出应该有一个变量numtweets:1和av ariable hastags与整个tweet hastats列表,其中包含1.示例Nuwtweets:1,hastags:“hast1”:1, “hast2”:2,“hast3”:1 1.-我可以将结果保存在一个集合中,以证明它运行良好而不是打印2.-如果不是,我必须做mapreduce,应该是什么功能减少,为什么不做任何事情,所以当执行它时,map函数的输出

Db.runCommand ({
                       MapReduce: "tweets",
                       Map: m,
                       Reduce: r,
                       Query: {"place.country_code": "AD"},
                       Out: {replace: "resultat5fi"}
                     });

任何建议,帮助,任何事情都将受到欢迎。

我建议你看看这个

这是使用mongodb轻松调试地图功能的方法。

  1. 首先,像你一样创建你的地图功能

  2. 然后定义一个将打印(或插入集合)的emit函数

插入到toto集合中的emit函数示例。

var emit = function(key, value) {
  db.toto.insert({key: key, value: value});
}
  1. 调用find函数并在每条记录上应用map函数

示例:

var myCursor = db.tweets.find( {} );

while (myCursor.hasNext()) {
    var doc = myCursor.next();
    map.apply(doc);
    print();
}
  1. 然后看看你的托托集合

这条路 :

db.toto.find()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM