예제 #1
0
 public MongoQueryWarpper ElemMatch(string name, MongoQueryWarpper query)
 {
     if (MongoQuery == Query.Null)
     {
         MongoQuery = Query.ElemMatch(name, query.MongoQuery);
         return(this);
     }
     MongoQuery = Query.And(MongoQuery, Query.ElemMatch(name, query.MongoQuery));
     return(this);
 }
예제 #2
0
 public MongoQueryWarpper Or(MongoQueryWarpper query)
 {
     if (MongoQuery == Query.Null)
     {
         MongoQuery = query.MongoQuery;
         return(this);
     }
     MongoQuery = Query.Or(MongoQuery, query.MongoQuery);
     return(this);
 }
예제 #3
0
        public static bool Remove(string connectionName, string database, string collection, MongoQueryWarpper querys)
        {
            if (querys == null)
            {
                return(false);
            }
            IMongoQuery mongoquery = querys.MongoQuery;

            var mongocollection = GetCollecion(connectionName, database, collection);

            mongocollection.Remove(mongoquery);
            return(true);
        }
예제 #4
0
        public static long Incr <T>(string connectionName, string database, string collection, MongoQueryWarpper querys, string field, long incr)
        {
            MongoUpdateWarpper updates = new MongoUpdateWarpper();

            updates.Incr(field, incr);

            IMongoQuery mongoquery = querys == null ? Query.Null : querys.MongoQuery;

            MD.Builders.UpdateBuilder updateBuilder = updates.MongoUpdateBuilder;
            if (updateBuilder != null)
            {
                var mongocollection = GetCollecion <T>(connectionName, database, collection);

                var result = mongocollection.Update(mongoquery, updates.MongoUpdateBuilder, UpdateFlags.Upsert);
                if (!result.UpdatedExisting)
                {
                    return(incr);
                }

                var entity   = mongocollection.FindOneAs <T>(querys.MongoQuery);
                var property = typeof(T).GetProperty(field);

                if (property == null)
                {
                    foreach (var mb in typeof(T).GetMembers())
                    {
                        var ca = mb.GetCustomAttributes(typeof(MB.Serialization.Attributes.BsonElementAttribute), true).FirstOrDefault();
                        if (ca == null)
                        {
                            continue;
                        }
                        if (((MB.Serialization.Attributes.BsonElementAttribute)ca).ElementName.Equals(field))
                        {
                            property = typeof(T).GetProperty(mb.Name);
                            break;
                        }
                    }
                }

                if (property == null)
                {
                    return(0);
                }

                return((long)(Convert.ChangeType(property.GetValue(entity, null), typeof(Int64))));
            }

            return(0);
        }
예제 #5
0
 public static bool Update <T>(string connectionName, string database, string collection, MongoQueryWarpper <T> querys, MongoUpdateWarpper <T> updates, MongoUpdateFlagsWarpper flgs = null) where T : new()
 {
     return(Update <T>(connectionName, database, collection, (MongoQueryWarpper)querys, (MongoUpdateWarpper)updates, flgs));
 }
예제 #6
0
        public static bool Update <T>(string connectionName, string database, string collection, MongoQueryWarpper querys, MongoUpdateWarpper updates, MongoUpdateFlagsWarpper flgs = null)
        {
            if (updates == null || updates.IsEmpty)
            {
                return(false);
            }

            IMongoQuery mongoquery = querys == null ? Query.Null : querys.MongoQuery;

            MD.Builders.UpdateBuilder updateBuilder = updates.MongoUpdateBuilder;
            if (updateBuilder != null)
            {
                var mongocollection = GetCollecion <T>(connectionName, database, collection);

                if (flgs == null)
                {
                    mongocollection.Update(mongoquery, updateBuilder);
                }
                else
                {
                    mongocollection.Update(mongoquery, updateBuilder, flgs.MongoUpdateFlags);
                }
                return(true);
            }

            return(false);
        }
예제 #7
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));
 }
예제 #8
0
 public MongoQueryWarpper <T> Or(MongoQueryWarpper <T> query)
 {
     base.Or(query);
     return(this);
 }
예제 #9
0
        public static List <T> Distinct <T>(string connectionName, string database, string collection, string key, MongoQueryWarpper querys)
        {
            var mongoquery      = querys == null ? Query.Null : querys.MongoQuery;
            var mongocollection = GetCollecion <T>(connectionName, database, collection);

            return(mongocollection.Distinct <T>(key, mongoquery).ToList());
        }
예제 #10
0
 public static long Count <T>(string connectionName, string database, string collection, MongoQueryWarpper <T> querys) where T : new()
 {
     return(Count(collection, database, collection, querys));
 }
예제 #11
0
        public static long Count(string connectionName, string database, string collection, MongoQueryWarpper querys)
        {
            var mongoquery      = querys == null ? Query.Null : querys.MongoQuery;
            var mongocollection = GetCollecion(connectionName, database, collection);

            var count = mongocollection.Count(mongoquery);

            return(count);
        }
예제 #12
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));
 }
예제 #13
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>());
        }
예제 #14
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));
 }
예제 #15
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>());
        }
예제 #16
0
 public static bool Remove <T>(string connectionName, string database, string collection, MongoQueryWarpper <T> querys) where T : new()
 {
     return(Remove(connectionName, database, collection, (MongoQueryWarpper)querys));
 }
예제 #17
0
 public MongoQueryWarpper <T> And(MongoQueryWarpper <T> query)
 {
     base.And(query);
     return(this);
 }
예제 #18
0
 public static List <T> Distinct <T>(string connectionName, string database, string collection, string key, MongoQueryWarpper <T> querys) where T : new()
 {
     return(Distinct <T>(connectionName, database, collection, key, (MongoQueryWarpper)querys));
 }
예제 #19
0
 public MongoQueryWarpper ElemMatch(Expression <Func <T, object> > name, MongoQueryWarpper query)
 {
     base.ElemMatch(MongoDBUtil.GetMongoElementField(name.Body), query);
     return(this);
 }
예제 #20
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]);
        }
예제 #21
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));
 }
예제 #22
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);
        }