예제 #1
0
        public List <BsonDocument> Kids(string parentId)
        {
            var         sort   = SortBy.Ascending("Created");
            MongoCursor cursor = _project.FindAs <BsonDocument>(Query.EQ(Constants.PARENT_ID, parentId))
                                 .SetSortOrder(sort);

            return(cursor.Cast <BsonDocument>().ToList());
        }
예제 #2
0
        public IEnumerable <AggregatedValue> Find(DateTime startDate, DateTime endDate, Dictionary <string, List <string> > props)
        {
            MongoCollection <StoredCounter> items = MongoDb.GetCollection <StoredCounter>("countersData");
            IMongoQuery   q      = Query.And(Query.GTE("date", startDate), Query.LT("date", endDate));
            FieldsBuilder fields = new FieldsBuilder();

            //fields.Include("date", "data.Max", "data.Min", "data.Count", "data.Avg", "data.Sum");
            fields.Include("date", "data");


            foreach (KeyValuePair <string, List <string> > prop in props)
            {
                string fieldName = "props." + prop.Key;
                fields.Include(fieldName);
                if (prop.Value.Count == 0)
                {
                    q = Query.And(q, Query.Exists(fieldName));
                }
                else if (prop.Value.Count == 1)
                {
                    q = Query.And(q, Query.EQ(fieldName, prop.Value.First()));
                }
                else
                {
                    q = Query.And(q, Query.In(fieldName, prop.Value.Cast <BsonString>()));
                }
            }

            MongoCursor cursor = items.Find(q);

            cursor.SetFields(fields);
            cursor.SetSortOrder(SortBy.Ascending("date"));
            Stopwatch sw    = Stopwatch.StartNew();
            var       found = cursor.Cast <object>().ToList();

            sw.Stop();
            Console.WriteLine(found.Count + " entries fetched from db in " + sw.ElapsedMilliseconds + " ms");
            sw.Restart();
            var parsed = found.Cast <StoredCounter>().Select(ParseAggregatedValue).ToList();

            sw.Stop();
            Console.WriteLine(parsed.Count + " entries parsed in " + sw.ElapsedMilliseconds + " ms");
            sw.Restart();
            var result = parsed.Compact().ToList();

            sw.Stop();
            Console.WriteLine(found.Count + " entries compacted to " + result.Count + " in " + sw.ElapsedMilliseconds + " ms");
            return(result);
        }