Exemple #1
0
        public void f()
        {
            string Map      = @"function(){
                                            var value = {
                                                Count:1,
                                                ValidCount: this.QA1_s1 <=10 ? 1:0
                                            };
                                            emit(this.flagname ,value);
                                        }";
            string Reduce   = @"function(key,values){
                                            var result = {Count:0,ValidCount:0}
                                            values.forEach(
                                                function(value){
                                                    result.Count += value.Count;
                                                    result.ValidCount += value.ValidCount;
                                                }
                                            );
                                            return result;
                                        }";
            string Finalize = @"function(key, reduced){
	                                        return reduced;
                                        }";

            IMongoDatabase db = Db.GetDb();
            IMongoCollection <BsonDocument> collection      = db.GetCollection <BsonDocument>("Data");
            MapReduceOptions <BsonDocument, BsonDocument> o = new MapReduceOptions <BsonDocument, BsonDocument>();
            BsonValue bv = BsonValue.Create("this.Sys_Upload_Time >= ISODate(\"2017-03-01T00:00:00Z\") && this.Sys_Upload_Time<= ISODate(\"2017-04-07T23: 59:59Z\")");

            o.Filter         = new BsonDocument("$where", bv);
            o.JavaScriptMode = true;
            o.OutputOptions  = MapReduceOutputOptions.Inline;
            o.Finalize       = new BsonJavaScript(Finalize);
            IAsyncCursor <BsonDocument> cursor = collection.MapReduce <BsonDocument>(new BsonJavaScript(Map), new BsonJavaScript(Reduce), o);
            JArray array = new JArray();

            if (cursor.MoveNext())
            {
                array = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(cursor.Current.ToJson());
            }
            return;
        }
Exemple #2
0
 public MongoDbHelper(string databaseName)
 {
     this.db    = Db.GetDb(databaseName);
     collection = db.GetCollection <BsonDocument>("Data");
 }