public void Execute(BsonDocument doc) { var occurance = new BsonDocument(doc.GetElement("time"), doc.GetElement("details")); doc.Remove("time"); doc.Remove("details"); var query = Query.And(Query.EQ("token", doc["token"]), Query.EQ("hash", doc["hash"])); UpdateBuilder ub = new UpdateBuilder(); ub.Push("occurances", occurance); ub.Set("token", doc["token"]); ub.Set("hash", doc["hash"]); ub.Set("level", doc["level"]); ub.Set("common", doc["common"]); ub.Set("lastTime", occurance["time"]); Events.Update(query, ub, UpdateFlags.Upsert); }
public void Save (AggregatedValue val) { MongoCollection<BsonDocument> items = MongoDb.GetCollection("countersData"); UpdateBuilder updateBuilder = new UpdateBuilder(); if (val.Count.HasValue) updateBuilder.Inc("data.Count", val.Count.Value); if (val.Sum.HasValue) updateBuilder.Inc("data.Sum", val.Sum.Value); if (val.Min.HasValue) updateBuilder.Push("data.Min", val.Min.Value); if (val.Max.HasValue) updateBuilder.Push("data.Max", val.Max.Value); if (val.Avg.HasValue) updateBuilder.Push("data.Avg", val.Avg.Value); if (val.Percentiles!=null || val.DistributionGroups!=null) updateBuilder.PushAll("data.Raw", val.RawValues.Select(v =>new BsonDouble(v))); IMongoQuery q = Query.And(Query.EQ("date", val.Date), Query.EQ("props.pCnt", val.Props.Count)); foreach (var prop in val.Props) { q = Query.And(q, Query.EQ("props."+prop.Key, prop.Value)); } items.Update(q, updateBuilder,UpdateFlags.Upsert,SafeMode.True); }