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 中添加 'query'?
引用:
https://docs.mongodb.com/manual/core/map-reduce/ https://godoc.org/github.com/globalsign/mgo#MapReduce
请您参考如下方法:
设法通过 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)