当前位置: 首页>>代码示例>>C#>>正文


C# MongoCollection.Save方法代码示例

本文整理汇总了C#中MongoCollection.Save方法的典型用法代码示例。如果您正苦于以下问题:C# MongoCollection.Save方法的具体用法?C# MongoCollection.Save怎么用?C# MongoCollection.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoCollection的用法示例。


在下文中一共展示了MongoCollection.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CoverDB

 public static void CoverDB(string player, MongoCollection oldPlayer, MongoCollection newPlayer)
 {
     Console.WriteLine("正在合并:" + player);
     int show = 0;
     int count = 0;
     var dates = oldPlayer.FindAllAs<BsonDocument>();
     foreach (var v in dates)
     {
         BsonValue key;
         if (v.TryGetValue("_id", out key))
         {
             if (newPlayer.Count(Query.EQ("_id", key)) <= 0)
             {
                 count++;
                 newPlayer.Save(v);
             }
         }
         show++;
         if (show % 1000 == 0)
         {
             Console.WriteLine("正在合并:" + show);
         }
     }
     Console.WriteLine(player + ":" + count);
 }
开发者ID:abel,项目名称:sinan,代码行数:25,代码来源:MergerDB.cs

示例2: AddUserEx

 /// <summary>
 ///     Adds a user to this database.
 /// </summary>
 /// <param name="user">The user.</param>
 public static void AddUserEx(MongoCollection Col, User user)
 {
     var document = Col.FindOneAs<BsonDocument>(Query.EQ("user", user.Username));
     if (document == null)
     {
         document = new BsonDocument("user", user.Username);
     }
     document["roles"] = user.roles;
     if (document.Contains("readOnly"))
     {
         document.Remove("readOnly");
     }
     //必须要Hash一下Password
     document["pwd"] = MongoUser.HashPassword(user.Username, user.Password);
     //OtherRole 必须放在Admin.system.users里面
     if (Col.Database.Name == MongoDbHelper.DATABASE_NAME_ADMIN)
     {
         document["otherDBRoles"] = user.otherDBRoles;
     }
     if (string.IsNullOrEmpty(user.Password))
     {
         document["userSource"] = user.userSource;
     }
     Col.Save(document);
 }
开发者ID:EricBlack,项目名称:MagicMongoDBTool,代码行数:29,代码来源:User.cs

示例3: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            string id = document.GetElement(DayStackStatsRepository.FieldNames.Id).Value.AsString;

            string[] parts = id.Split('/');
            if (parts.Length != 2)
                return;

            string errorStackId = parts[0];
            var stackCollection = Database.GetCollection(ErrorStackRepository.CollectionName);
            var errorStack = stackCollection.FindOne(Query.EQ(ErrorStackRepository.FieldNames.Id, new BsonObjectId(new ObjectId(errorStackId))));

            if (errorStack != null) {
                var projectId = errorStack.GetElement(ErrorStackRepository.FieldNames.ProjectId).Value;
                document.Set(DayStackStatsRepository.FieldNames.ProjectId, projectId);
            }

            document.Set(DayStackStatsRepository.FieldNames.ErrorStackId, new BsonObjectId(new ObjectId(errorStackId)));

            var emptyBlocks = new List<BsonElement>();
            BsonDocument minuteBlocks = document.GetValue(DayStackStatsRepository.FieldNames.MinuteStats).AsBsonDocument;
            foreach (BsonElement b in minuteBlocks.Elements) {
                if (b.Value.AsInt32 == 0)
                    emptyBlocks.Add(b);
            }

            foreach (BsonElement b in emptyBlocks)
                minuteBlocks.RemoveElement(b);

            collection.Save(document);
        }
开发者ID:GuilhermeMorais,项目名称:Exceptionless,代码行数:30,代码来源:v1.0.1-v1.0.8_Migration.cs

示例4: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            bool renamed = false;
            BsonDocument currentDoc = document;
            while (currentDoc != null) {
                if (currentDoc.Contains(ErrorRepository.FieldNames.ExtendedData)) {
                    BsonValue extendedData = currentDoc.GetElement(ErrorRepository.FieldNames.ExtendedData).Value;
                    if (extendedData.IsBsonArray) {
                        var newDoc = new BsonDocument(extendedData.AsBsonArray.Where(a => a.AsBsonArray.Count == 2).Select(a => new BsonElement(a.AsBsonArray[0].AsString.Replace('.', '_'), a.AsBsonArray[1])));
                        currentDoc.Set(ErrorRepository.FieldNames.ExtendedData, newDoc);
                        extendedData = newDoc;
                    }

                    renamed |= extendedData.AsBsonDocument.ChangeName("ExtraExceptionProperties", ExtendedDataDictionary.EXCEPTION_INFO_KEY);
                    renamed |= extendedData.AsBsonDocument.ChangeName("ExceptionInfo", ExtendedDataDictionary.EXCEPTION_INFO_KEY);
                    renamed |= extendedData.AsBsonDocument.ChangeName("TraceInfo", ExtendedDataDictionary.TRACE_LOG_KEY);
                }

                if (currentDoc.Contains(ErrorRepository.FieldNames.Inner)) {
                    BsonValue v = currentDoc.GetElement(ErrorRepository.FieldNames.Inner).Value;
                    currentDoc = !v.IsBsonNull ? v.AsBsonDocument : null;
                } else
                    currentDoc = null;
            }

            if (renamed)
                collection.Save(document);
        }
开发者ID:khoussem,项目名称:Exceptionless,代码行数:27,代码来源:v1.0.14.cs

示例5: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
        {
            if (document.Contains("ErrorCount"))
                document.ChangeName("ErrorCount", "EventCount");

            if (document.Contains("TotalErrorCount"))
                document.ChangeName("TotalErrorCount", "TotalEventCount");

            if (document.Contains("LastErrorDate"))
                document.ChangeName("LastErrorDate", "LastEventDate");

            if (document.Contains("MaxErrorsPerMonth"))
                document.ChangeName("MaxErrorsPerMonth", "MaxEventsPerMonth");

            if (document.Contains("SuspensionCode")) {
                var value = document.GetValue("SuspensionCode");
                document.Remove("SuspensionCode");

                SuspensionCode suspensionCode;
                if (value.IsString && Enum.TryParse(value.AsString, true, out suspensionCode))
                    document.Set("SuspensionCode", suspensionCode);
            }

            collection.Save(document);
        }
开发者ID:arpitgold,项目名称:Exceptionless,代码行数:25,代码来源:v1.0.32.cs

示例6: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            decimal price = 0m;
            if (!document.Contains(OrganizationRepository.FieldNames.PlanId))
                return;

            switch (document.GetValue(OrganizationRepository.FieldNames.PlanId).AsString) {
                case "EX_SMALL":
                    price = BillingManager.SmallPlan.Price;
                    break;
                case "EX_MEDIUM":
                    price = BillingManager.MediumPlan.Price;
                    break;
                case "EX_LARGE":
                    price = BillingManager.LargePlan.Price;
                    break;
            }

            if (price == 0m)
                return;

            if (!document.Contains(OrganizationRepository.FieldNames.BillingPrice))
                document.Add(OrganizationRepository.FieldNames.BillingPrice, new BsonString(price.ToString()));
            else
                document.Set(OrganizationRepository.FieldNames.BillingPrice, new BsonString(price.ToString()));

            collection.Save(document);
        }
开发者ID:khoussem,项目名称:Exceptionless,代码行数:27,代码来源:v1.0.23.cs

示例7: UpdateDocument

 public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
 {
     var projectIds = document.GetValue("ProjectIds").AsBsonArray.Select(p => p.AsInt32).ToList();
     document.Remove("ProjectIds");
     document.Add("ProjectIds", new BsonArray(projectIds.Select(x => x.ToString())));
     collection.Save(document);
 }
开发者ID:apxnowhere,项目名称:Encore,代码行数:7,代码来源:ChangeFieldProjectIdToString.cs

示例8: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            ObjectId organizationId = document.GetValue(ProjectRepository.FieldNames.OrganizationId).AsObjectId;
            var users = Database.GetCollection(UserRepository.CollectionName)
                .Find(Query.In(UserRepository.FieldNames.OrganizationIds, new List<BsonValue> {
                    organizationId
                }))
                .SetFields(ProjectRepository.FieldNames.Id).ToList();

            if (!document.Contains(ProjectRepository.FieldNames.NotificationSettings))
                document.Add(ProjectRepository.FieldNames.NotificationSettings, new BsonDocument());

            BsonDocument settings = document.GetValue(ProjectRepository.FieldNames.NotificationSettings).AsBsonDocument;
            foreach (var user in users) {
                var userId = user.GetValue(ProjectRepository.FieldNames.Id).AsObjectId.ToString();
                if (!settings.Contains(userId))
                    settings.Add(userId, new BsonDocument());

                var userSettings = settings.GetValue(userId).AsBsonDocument;
                if (!userSettings.Contains("SendDailySummary"))
                    userSettings.Add("SendDailySummary", new BsonBoolean(true));
                else
                    userSettings.Set("SendDailySummary", new BsonBoolean(true));
            }

            collection.Save(document);
        }
开发者ID:khoussem,项目名称:Exceptionless,代码行数:26,代码来源:v1.0.22.cs

示例9: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (!document.Contains(UserRepository.FieldNames.IsEmailAddressVerified))
                document.Add(UserRepository.FieldNames.IsEmailAddressVerified, new BsonBoolean(true));
            else
                document.Set(UserRepository.FieldNames.IsEmailAddressVerified, new BsonBoolean(true));

            collection.Save(document);
        }
开发者ID:khoussem,项目名称:Exceptionless,代码行数:8,代码来源:v1.0.17.cs

示例10: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (document.Contains("OverageHours"))
                document.Remove("OverageHours");

            if (document.Contains("Usage"))
                document.Remove("Usage");

            collection.Save(document);
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:9,代码来源:v1.0.30.cs

示例11: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (collection.IndexExistsByName("Username_1"))
                collection.DropIndexByName("Username_1");

            if (document.Contains("Username"))
                document.Remove("Username");

            collection.Save(document);
        }
开发者ID:Ripper555,项目名称:Exceptionless,代码行数:9,代码来源:v1.0.16.cs

示例12: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (!document.Contains(ErrorStackRepository.FieldNames.SignatureInfo))
                return;

            var signatureInfo = document.GetElement(ErrorStackRepository.FieldNames.SignatureInfo).Value.AsBsonDocument;
            bool renamed = signatureInfo.ChangeName("AppPath", "Path");

            if (renamed)
                collection.Save(document);
        }
开发者ID:khoussem,项目名称:Exceptionless,代码行数:10,代码来源:v1.0.11_Migration.cs

示例13: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (document.Contains("OverageDays"))
                document.Remove("OverageDays");

            document.ChangeName("MaxErrorsPerDay", "MaxErrorsPerMonth");
            var maxErrorsPerMonth = document.GetValue("MaxErrorsPerMonth").AsInt32;
            if (maxErrorsPerMonth > 0)
                document.Set("MaxErrorsPerMonth", maxErrorsPerMonth * 30);

            collection.Save(document);
        }
开发者ID:jrheault,项目名称:Exceptionless,代码行数:11,代码来源:v1.0.29.cs

示例14: AddEvent

 private void AddEvent(ObjectId id, int statusCode, MongoCollection<Entity> collection)
 {
     var entity = collection.FindOneById(id);
     entity.StatusCode = statusCode;
     entity.Events.Add(new EntityEvent
     {
         CreatedAt = DateTime.Now,
         Description = Guid.NewGuid().ToString(),
         StatusCode = statusCode
     });
     collection.Save(entity);
 }
开发者ID:qwert789,项目名称:codegallery,代码行数:12,代码来源:ReuseEntityRepositoryTests.cs

示例15: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (!document.Contains(ErrorRepository.FieldNames.RequestInfo))
                return;

            BsonDocument requestInfo = document.GetElement(ErrorRepository.FieldNames.RequestInfo).Value.AsBsonDocument;
            if (!requestInfo.Contains("frm"))
                return;

            requestInfo.Add(ErrorRepository.FieldNames.PostData, new BsonString(requestInfo.GetElement("frm").Value.ToJson()));
            requestInfo.Remove("frm");

            collection.Save(document);
        }
开发者ID:khoussem,项目名称:Exceptionless,代码行数:13,代码来源:v1.0.20.cs


注:本文中的MongoCollection.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。