我正在尝试用c#2.3驱动程序执行一个非常简单的mongodb mapreduce,但我得到了一个例外:
代码是:`
string StringDeConexao =“mongodb://10.0.0.211:27017”;
MongoClient client = new MongoClient(StringDeConexao);
var servidor = client.GetDatabase("distribuicoes");
var collection = servidor.GetCollection<BsonDocument>("processo");
var mapa = new BsonJavaScript(@"function() {
var chave = this.Natureza;
var valor = {
this.NumeroDoProcesso,
this.Comarca,
this.Natureza,
this.Classe,
this.Assunto.AssuntoPrincipal,
this.Autor.Nome,
this.Autor.TipoDePessoa,
this.CodigoCnaeAutor,
this.Reu.Nome,
this.Reu.TipoDePessoa,
this.CodigoCnaeReu,
count:1
};
emit(chave, valor);
};");
var reducao = new BsonJavaScript(@"function(chave, valores) {
var ObjetoReduzido = {
Natureza: chave,
count: 0
};
valores.ForEach(function(valor) {
ObjetoReduzido.count+= valor.count;
};
return Objeto.Reduzido;
};");
var pesquisa = Builders<BsonDocument>.Filter.Regex("Natureza", new BsonRegularExpression("c[ií]vel", "i"));
var option = new MongoDB.Driver.MapReduceOptions<BsonDocument, String>();
option.Filter = pesquisa;
option.OutputOptions = Inline;
var result = collection.MapReduce(mapa, reducao, option);`
它适用于mongodb shell。
感谢您的帮助。
答案 0 :(得分:0)
你的ForEach()格式错误,你在每个函数上都有(带)分号。