import "github.com/globalsign/mgo"job := &mgo.MapReduce{ Map: "function() { emit(this.name, 1) }", Reduce: "function(key, values) { return Array.sum(values) }", Out: "res",}_, err = c.Find(nil).MapReduce(job, nil)如何将“查询”添加到上面的 golang mgo mapreduce ?参考:https://docs.mongodb.com/manual/core/map-reduce/ https://godoc.org/github.com/globalsign/mgo#MapReduce
2 回答
茅侃侃
TA贡献1842条经验 获得超21个赞
设法通过 MongoDb 官方 godriver 完成此任务
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
par := bson.D{
{"mapreduce", "audit"},
{"map", " function() { emit( this.name , 1 ); }"},
{"reduce", "function(key, arr) { return Array.sum(arr); }"},
{"out", "mr3"},
{"query", bson.D{{"status", "SUCCESS"}}},
}
sr := db.RunCommand(nil, par)
暮色呼如
TA贡献1853条经验 获得超9个赞
MapReduce
是 Find 返回的 Query 结构的函数。因此,为了将 MapReduce 应用于查询结果,只需将查询文档添加到 find 函数中即可:
c.Find(query).MapReduce(job,result)
- 2 回答
- 0 关注
- 128 浏览
添加回答
举报
0/150
提交
取消