2016-12-13 65 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()是()形式不正確,而且每個函數都有(後綴)分號。

相關問題