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


C# BsonDocument.Set方法代码示例

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


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

示例1: UpdateDocument

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

            string[] parts = id.Split('/');
            if (parts.Length > 0)
                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(MonthStackStatsRepository.FieldNames.ProjectId, projectId);
            }

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

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

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

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

示例2: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            BsonValue value;
            if (document.TryGetValue("EventTypes", out value) && value.IsBsonArray) {
                var types = value.AsBsonArray;
                if (types.Contains(new BsonString("ErrorRegression"))) {
                    types.Remove(new BsonString("ErrorRegression"));
                    types.Add(new BsonString("StackRegression"));
                    document.Set("EventTypes", types);
                }
            }

            if (!document.Contains("Version"))
                document.Set("Version", "1.0");

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

示例3: CreateDoc

        private BsonDocument CreateDoc()
        {
            // create same object, but using BsonDocument
            var doc = new BsonDocument();
            doc["_id"] = 123;
            doc["FirstString"] = "BEGIN this string \" has \" \t and this \f \n\r END";
            doc["CustomerId"] = Guid.NewGuid();
            doc["Date"] = new DateTime(2015, 1, 1);
            doc["MyNull"] = null;
            doc["Items"] = new BsonArray();
            doc["MyObj"] = new BsonDocument();
            doc["EmptyString"] = "";
            var obj = new BsonDocument();
            obj["Qtd"] = 3;
            obj["Description"] = "Big beer package";
            obj["Unit"] = 1299.995;
            doc["Items"].AsArray.Add(obj);
            doc["Items"].AsArray.Add("string-one");
            doc["Items"].AsArray.Add(null);
            doc["Items"].AsArray.Add(true);
            doc["Items"].AsArray.Add(DateTime.Now);

            doc.Set("MyObj.IsFirstId", true);

            return doc;
        }
开发者ID:ktaranov,项目名称:LiteDB,代码行数:26,代码来源:JsonTest.cs

示例4: 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

示例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: ToBsonDocument

        public static BsonDocument ToBsonDocument(this XElement xElement)
        {
            var bsonDocument = new BsonDocument();

            var type = xElement.Name.ToString();
            bsonDocument.Add(Constants._TYPE, type);
            var mainId = xElement.Attribute(Constants._ID) != null ? xElement.Attribute(Constants._ID).Value : null;

            foreach (XAttribute attribure in xElement.Attributes())
            {
                var key = attribure.Name.ToString();
                var value = attribure.Value;
                if (bsonDocument.Contains(key))
                    bsonDocument.Set(key, value);
                else
                    bsonDocument.Add(key, value);
            }
            foreach (XElement kid in xElement.Descendants())
            {
                var id = kid.Attribute(Constants._ID);
                if (id == null || mainId == null)
                {
                    bsonDocument.Add(kid.Name.ToString(), kid.ToBsonDocument());
                }
                else
                {
                    kid.SetAttributeValue(Constants.PARENT_ID, mainId);
                    DBFactory.GetData().Save(kid);
                }
            }
            return bsonDocument;
        }
开发者ID:bperreault,项目名称:autox,代码行数:32,代码来源:BsonDocumentExt.cs

示例7: CreateDoc

        private BsonDocument CreateDoc()
        {
            // create same object, but using BsonDocument
            var doc = new BsonDocument();
            doc["_id"] = 123;
            doc["FirstString"] = "BEGIN this string \" has \" \t and this \f \n\r END";
            doc["CustomerId"] = Guid.NewGuid();
            doc["Date"] = DateTime.Now;
            doc["MyNull"] = null;
            doc["EmptyObj"] = new BsonDocument();
            doc["EmptyString"] = "";
            doc["maxDate"] = DateTime.MaxValue;
            doc["minDate"] = DateTime.MinValue;

            doc.Set("Customer.Address.Street", "Av. Caçapava, Nº 122");

            doc["Items"] = new BsonArray();

            doc["Items"].AsArray.Add(new BsonDocument());
            doc["Items"].AsArray[0].AsDocument["Qtd"] = 3;
            doc["Items"].AsArray[0].AsDocument["Description"] = "Big beer package";
            doc["Items"].AsArray[0].AsDocument["Unit"] = (double)10 / (double)3;

            doc["Items"].AsArray.Add("string-one");
            doc["Items"].AsArray.Add(null);
            doc["Items"].AsArray.Add(true);
            doc["Items"].AsArray.Add(DateTime.Now);

            return doc;
        }
开发者ID:AshishVishwakarma,项目名称:LiteDB,代码行数:30,代码来源:BsonTest.cs

示例8: applyUpdateCommands

        public static void applyUpdateCommands(BsonDocument doc, BsonDocument change_spec)
        {
            foreach (var field in change_spec) {
                if (field.Name.Length > 0 && field.Name[0] == '$') {
                    // update command
                    switch (field.Name) {
                        case "$set":
                            _applySet(doc, field.Value.AsBsonDocument);
                            break;
                        case "$inc":
                            _applyInc(doc, field.Value.AsBsonDocument);
                            break;
                        case "$unset":
                            _applyUnset(doc, field.Value.AsBsonDocument);
                            break;
                        case "$push":
                        case "$pushAll":
                        case "$addToSet":
                        case "$pop":
                        case "$pull":
                        case "$pullAll":
                        case "$rename":
                        case "$":
                            throw new Exception("unimplemented update operator: " + field.Name);
                        default:
                            throw new Exception("unknown update operator: " + field.Name);
                    }

                } else {
                    // field replace
                    if (field.Value.BsonType == BsonType.Document) {
                        if (!doc.Contains(field.Name) ||
                            doc.GetElement(field.Name).Value.BsonType != BsonType.Document) {
                            // make a document to hold the recurse
                            doc.Set(field.Name, new BsonDocument());
                        }
                        // recursively apply changes
                        applyUpdateCommands(doc.GetElement(field.Name).Value.AsBsonDocument,
                            field.Value.AsBsonDocument);
                    } else {
                        // otherwise just apply the change directly
                        doc.Set(field.Name, field.Value);
                    }
                }
            }
        }
开发者ID:jeske,项目名称:StepsDB-alpha,代码行数:46,代码来源:BsonHelper.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("EmailNotificationsEnabled")) {
                bool emailNotificationsEnabled = document.GetValue("EmailNotificationsEnabled").AsBoolean;
                while (document.Contains("EmailNotificationsEnabled"))
                    document.Remove("EmailNotificationsEnabled");

                document.Set("EmailNotificationsEnabled", emailNotificationsEnabled);
            }

            if (document.Contains("EmailAddress")) {
                string emailAddress = document.GetValue("EmailAddress").AsString;
                if (!String.IsNullOrWhiteSpace(emailAddress))
                    document.Set("EmailAddress", emailAddress.ToLowerInvariant().Trim());
            }

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

示例11: 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("MaxErrorsPerDay")) {
                int maxErrorsPerDay = -1;
                var maxErrorsPerDayElement = document.GetValue("MaxErrorsPerDay");
                if (maxErrorsPerDayElement.IsInt32)
                    maxErrorsPerDay = maxErrorsPerDayElement.AsInt32;
                else if (maxErrorsPerDayElement.IsInt64)
                    maxErrorsPerDay = (int)maxErrorsPerDayElement.AsInt64;

                document.Set("MaxEventsPerMonth", maxErrorsPerDay > 0 ? maxErrorsPerDay * 30 : -1);
                document.Remove("MaxErrorsPerDay");
            }

            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);
            }

            if (document.Contains("PlanId")) {
                string planId = document.GetValue("PlanId").AsString;
                var currentPlan = BillingManager.GetBillingPlan(planId);

                document.Set("PlanName", currentPlan != null ? currentPlan.Name : planId);
                document.Set("PlanDescription", currentPlan != null ? currentPlan.Description : planId);
            }

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

示例12: Persist

        public void Persist(BsonDocument document)
        {
            document.Set("timestamp", DateTime.Now);

            var id = Builders<BsonDocument>.Filter.Eq("_id", document.GetValue("_id"));

            _collection.DeleteOneAsync(id).Wait();

            _collection.InsertOneAsync(document).Wait();
        }
开发者ID:dream-365,项目名称:lemon,代码行数:10,代码来源:MongoDBPersistence.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: UpdateDocument

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

            var occurrenceDateArray = document.GetValue(ErrorRepository.FieldNames.OccurrenceDate).AsBsonArray;
            var localTicks = occurrenceDateArray[0].AsInt64;
            var offset = TimeSpan.FromMinutes(occurrenceDateArray[1].AsInt32);
            occurrenceDateArray[0] = localTicks + -offset.Ticks;

            document.Set(ErrorRepository.FieldNames.OccurrenceDate, occurrenceDateArray);

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

示例15: RunAsync

        public async Task RunAsync()
        {
            await _askerActivityCollection.Find("{month: '" + _month + "'}")
                .Project("{_id: 1, id: 1}")
                .ForEachAsync(async (item)=> {
                    var objId = item.GetElement("_id").Value.AsObjectId;
                    var id = item.GetElement("id").Value.AsString;

                    var document = new BsonArray();

                    await _askerTagCollection.Find("{'_id.user': '" + id + "', '_id.month': '" + _month + "'}")
                                       .ForEachAsync((userTag) => {
                                           var temp = new BsonDocument();

                                           var _id = userTag.GetElement("_id").Value.AsBsonDocument;

                                           var value = userTag.GetElement("value").Value.AsBsonDocument;

                                           var tag = _id.GetElement("tag").Value;

                                           var count = value.GetElement("count").Value;

                                           temp.Set("name", tag);

                                           temp.Set("count", count);

                                           document.Add(temp);
                                       });

                    var lookup = Builders<BsonDocument>.Filter.Eq("_id", objId);

                    var set = Builders<BsonDocument>.Update.Set("tags", document);

                    await _askerActivityCollection.UpdateOneAsync(lookup, set);

                    Console.WriteLine("user id: " + id);
                });
        }
开发者ID:Myfreedom614,项目名称:toolkit,代码行数:38,代码来源:UpdateMonthlyAskerTagsToAskerActivityStep.cs


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