【发布时间】:2016-12-13 20:47:01
【问题描述】:
我正在尝试使用 c# 2.3 驱动程序执行一个非常简单的 mongodb mapreduce,但出现异常:
代码是:`
字符串 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。
感谢您的帮助。
【问题讨论】:
-
它说“附加信息:命令 mapreduce 失败:异常:SyntaxError: Unexpected token ..”但我真的看不出有哪里。
-
能否请您发布
mongo shell版本的 mapreduce ?我认为这里的问题是由于valor的JSON 语法。它需要key:value对。
标签: c# mongodb mapreduce driver