public static MongoQueryBuilder BuildFrom(SimpleQuery query)
        {
            var builder = new MongoQueryBuilder();

            builder.Build(query);
            return(builder);
        }
Exemple #2
0
        public IEnumerable <IDictionary <string, object> > Find(MongoCollection <BsonDocument> collection, SimpleQuery query, out IEnumerable <SimpleQueryClauseBase> unhandledClauses)
        {
            var builder = MongoQueryBuilder.BuildFrom(query);

            unhandledClauses = builder.UnprocessedClauses;

            if (builder.IsTotalCountQuery)
            {
                long count;
                if (builder.Criteria == null)
                {
                    count = collection.Count();
                }
                else
                {
                    count = collection.Count(_expressionFormatter.Format(builder.Criteria));
                }

                //TODO: figure out how to make count a long
                builder.SetTotalCount((int)count);
            }

            if (!builder.SkipCount.HasValue && builder.TakeCount.HasValue && builder.TakeCount.Value == 1)
            {
                return new[] { FindOne(collection, builder.Criteria) }
            }
            ;

            var cursor = CreateCursor(collection, builder.Criteria);

            ApplyFields(cursor, builder.Columns);
            ApplySorting(cursor, builder.Order);
            ApplySkip(cursor, builder.SkipCount);
            ApplyTake(cursor, builder.TakeCount);

            var aliases = builder.Columns.OfType <ObjectReference>().ToDictionary(x => ExpressionFormatter.GetFullName(x), x => x.GetAlias());

            return(cursor.Select(x => x.ToSimpleDictionary(aliases)));
        }
 public static MongoQueryBuilder BuildFrom(SimpleQuery query)
 {
     var builder = new MongoQueryBuilder();
     builder.Build(query);
     return builder;
 }