【问题标题】:mongodb mapreduce can save emit into collection?mongodb mapreduce可以将发射保存到集合中吗?
【发布时间】:2017-04-26 10:14:43
【问题描述】:

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

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 函数的输出应该有一个 variable numtweets: 1 和一个 variable hastags,其中包含 1 的整个 tweet hastats 列表。 例子 Nuwtweets: 1, hastags: "hast1": 1, "hast2": 2, "hast3": 1 1.-我可以将结果保存在一个集合中,以证明它运行良好而不是打印 2.-如果不是如果我必须做mapreduce,那么函数reduce应该是什么,为什么不做任何事情,所以在执行这个时,map函数的输出

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

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

【问题讨论】:

    标签: mongodb dictionary mapreduce


    【解决方案1】:

    我建议你看看this

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

    1. 首先,像以前一样创建地图函数

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

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

    var emit = function(key, value) {
      db.toto.insert({key: key, value: value});
    }
    
    1. 调用查找函数并将地图函数应用于每条记录

    例子:

    var myCursor = db.tweets.find( {} );
    
    while (myCursor.hasNext()) {
        var doc = myCursor.next();
        map.apply(doc);
        print();
    }
    
    1. 那就看看你的toto收藏

    这样:

    db.toto.find()
    

    【讨论】:

      猜你喜欢
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 2015-06-13
      • 1970-01-01
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多