Ejemplo n.º 1
0
 public MongoUpdateWarpper Combine(MongoUpdateWarpper other)
 {
     MongoUpdateBuilder = MongoUpdateBuilder.Combine(other.MongoUpdateBuilder);
     if (_isempty)
     {
         _isempty = other.IsEmpty;
     }
     return(this);
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public MongoUpdateWarpper <T> Combine(MongoUpdateWarpper <T> other)
 {
     base.Combine(other);
     return(this);
 }
Ejemplo n.º 4
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));
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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));
 }
Ejemplo n.º 7
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>());
        }