Example #1
0
 public static T FindOne <T>(string connectionName, string database, string collection, MongoQueryWarpper <T> querys, MongoFieldSelecter <T> fields, MongoSortWarpper sorts) where T : new()
 {
     return(FindOne <T>(connectionName, database, collection, (MongoQueryWarpper)querys, fields == null ? null : fields.GetFields(), sorts));
 }
Example #2
0
 public static List <T> FindAll <T>(string connectionName, string database, string collection, MongoSortWarpper <T> sorts) where T : new()
 {
     return(FindAll <T>(connectionName, database, collection, (MongoSortWarpper)sorts));
 }
Example #3
0
        public static T FindOne <T>(string connectionName, string database, string collection, MongoQueryWarpper querys, string[] fields, MongoSortWarpper sorts)
        {
            var mongoquery      = querys == null ? Query.Null : querys.MongoQuery;
            var mongocollection = GetCollecion <T>(connectionName, database, collection);

            var cur = mongocollection.FindAs <T>(mongoquery);

            if (fields != null && fields.Length > 0)
            {
                cur = cur.SetFields(fields);
            }
            if (sorts != null)
            {
                cur = cur.SetSortOrder(sorts.MongoSortBy);
            }

            var list = cur.SetLimit(1).ToList();

            if (list == null || list.Count == 0)
            {
                return(default(T));
            }

            return(list[0]);
        }
Example #4
0
 public static T FindAndRemove <T>(string connectionName, string database, string collection, MongoQueryWarpper <T> querys, MongoSortWarpper <T> sorts) where T : new()
 {
     return(FindAndRemove <T>(connectionName, database, collection, (MongoQueryWarpper)querys, (MongoSortWarpper)sorts));
 }
Example #5
0
        public static List <T> FindAll <T>(string connectionName, string database, string collection, MongoSortWarpper sorts)
        {
            var mongocollection = GetCollecion <T>(connectionName, database, collection);

            if (sorts == null || sorts.MongoSortBy == SortBy.Null)
            {
                var list = mongocollection.FindAllAs <T>().ToList();

                return(list);
            }
            else
            {
                var list = mongocollection.FindAllAs <T>().SetSortOrder(sorts.MongoSortBy).ToList();

                return(list);
            }
        }
Example #6
0
        public static T FindAndRemove <T>(string connectionName, string database, string collection, MongoQueryWarpper querys, MongoSortWarpper sorts)
        {
            var mongoquery      = querys == null ? Query.Null : querys.MongoQuery;
            var mongosort       = (sorts == null || sorts.MongoSortBy == SortBy.Null) ? SortBy.Null : sorts.MongoSortBy;
            var mongocollection = GetCollecion <T>(connectionName, database, collection);
            var retresult       = mongocollection.FindAndRemove(new FindAndRemoveArgs {
                Query = mongoquery, SortBy = mongosort
            });

            return(retresult.GetModifiedDocumentAs <T>());
        }
Example #7
0
 public static T FindAndModify <T>(string connectionName, string database, string collection, MongoQueryWarpper <T> querys, MongoUpdateWarpper <T> updates, MongoSortWarpper <T> sorts, bool returnNew, bool upsert) where T : new()
 {
     return(FindAndModify <T>(connectionName, database, collection, (MongoQueryWarpper)querys, (MongoUpdateWarpper)updates, (MongoSortWarpper)sorts, returnNew, upsert));
 }
Example #8
0
        public static T FindAndModify <T>(string connectionName, string database, string collection, MongoQueryWarpper querys, MongoUpdateWarpper updates, MongoSortWarpper sorts, bool returnNew, bool upsert)
        {
            var mongoquery      = querys == null ? Query.Null : querys.MongoQuery;
            var mongosort       = (sorts == null || sorts.MongoSortBy == SortBy.Null) ? SortBy.Null : sorts.MongoSortBy;
            var mongocollection = GetCollecion <T>(connectionName, database, collection);
            var retresult       = mongocollection.FindAndModify(mongoquery, mongosort, updates.MongoUpdateBuilder, returnNew, upsert);

            return(retresult.GetModifiedDocumentAs <T>());
        }
Example #9
0
 public static List <T> Find <T>(string connectionName, string database, string collection, MongoQueryWarpper <T> querys, int pageindex, int pagesize, MongoFieldSelecter <T> fieldselecter, MongoSortWarpper <T> sorts) where T : new()
 {
     return(Find <T>(connectionName, database, collection, (MongoQueryWarpper)querys, pageindex, pagesize, fieldselecter == null ? null : fieldselecter.GetFields(), (MongoSortWarpper)sorts));
 }
Example #10
0
        public static List <T> Find <T>(string connectionName, string database, string collection, MongoQueryWarpper querys, int pageindex, int pagesize, string[] fields, MongoSortWarpper sorts)
        {
            var mongoquery      = querys == null ? Query.Null : querys.MongoQuery;
            var mongocollection = GetCollecion <T>(connectionName, database, collection);
            var mongosortby     = (sorts == null || sorts.MongoSortBy == SortBy.Null) ? SortBy.Null : sorts.MongoSortBy;
            int skip            = (pageindex - 1) * pagesize;

            MongoCursor <T> mongocursor = null;

            if (mongosortby != SortBy.Null)
            {
                mongocursor = mongocollection.FindAs <T>(mongoquery).SetSkip(skip).SetLimit(pagesize).SetSortOrder(mongosortby);
            }
            else
            {
                mongocursor = mongocollection.FindAs <T>(mongoquery).SetSkip(skip).SetLimit(pagesize);
            }

            if (fields != null && fields.Length > 0)
            {
                mongocursor = mongocursor.SetFields(fields);
            }

            List <T> list = mongocursor.ToList();

            return(list);
        }