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);
 }
 public MongoQueryWarpper Or(MongoQueryWarpper query)
 {
     if (MongoQuery == Query.Null)
     {
         MongoQuery = query.MongoQuery;
         return(this);
     }
     MongoQuery = Query.Or(MongoQuery, query.MongoQuery);
     return(this);
 }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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));
 }
Beispiel #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);
        }
Beispiel #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));
 }
Beispiel #8
0
 public MongoQueryWarpper <T> Or(MongoQueryWarpper <T> query)
 {
     base.Or(query);
     return(this);
 }
Beispiel #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());
        }
Beispiel #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));
 }
Beispiel #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);
        }
Beispiel #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));
 }
Beispiel #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>());
        }
Beispiel #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));
 }
Beispiel #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>());
        }
Beispiel #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));
 }
Beispiel #17
0
 public MongoQueryWarpper <T> And(MongoQueryWarpper <T> query)
 {
     base.And(query);
     return(this);
 }
Beispiel #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));
 }
Beispiel #19
0
 public MongoQueryWarpper ElemMatch(Expression <Func <T, object> > name, MongoQueryWarpper query)
 {
     base.ElemMatch(MongoDBUtil.GetMongoElementField(name.Body), query);
     return(this);
 }
Beispiel #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]);
        }
Beispiel #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));
 }
Beispiel #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);
        }