MongoDB MapReduce函数中的查询

MongoDB MapReduce函数中的查询,第1张

MongoDB MapReduce函数中的查询

您可能要尝试以下 *** 作

    String map = "function() { " +      "    var regex1 = new RegExp('autobiography', 'i'); " +      "    var regex2 = new RegExp('book', 'i'); " +      "    if (regex1.test(this.tweet) ) " +      "         emit('Autobiography Tweet', 1); " +      "    else if (regex2.test(this.tweet) ) " +      "         emit('Book Tweet', 1); " +      "    else " +      "       emit('Uncategorized Tweet', 1); " +      "}";    String reduce = "function(key, values) { " +         "    return Array.sum(values); " +         "}";    MapReduceCommand cmd = new MapReduceCommand(collection, map, reduce,  null, MapReduceCommand.OutputType.INLINE, null);    MapReduceOutput out = collection.mapReduce(cmd);    try {        for (DBObject o : out.results()) { System.out.println(o.toString());       }    } catch (Exception e) {        e.printStackTrace();    }


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5164850.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-18
下一篇2022-11-18

发表评论

登录后才能评论

评论列表(0条)

    保存