2016-12-13 21 views
1

我想用C#2.3驱动程序执行一个非常简单的MongoDB MapReduce的,但我发现了异常:DOTNET MongoDB的驱动器2.3和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外壳。

感谢任何帮助。

+0

哪个例外? – McNets

+0

它说:“附加信息:命令mapreduce失败:异常:SyntaxError:意外的标记..”但我真的不知道哪里有。 – user1548763

+0

您可以发布mapreduce的'mongo shell'版本吗?我认为这里的问题是由于'valor'的JSON语法造成的。它需要'key:value'对。 –

回答

0

您的ForEach()是()形式不正确,而且每个函数都有(后缀)分号。