當前位置: 首頁>>代碼示例>>C#>>正文


C# BsonDocument.GetElement方法代碼示例

本文整理匯總了C#中BsonDocument.GetElement方法的典型用法代碼示例。如果您正苦於以下問題:C# BsonDocument.GetElement方法的具體用法?C# BsonDocument.GetElement怎麽用?C# BsonDocument.GetElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BsonDocument的用法示例。


在下文中一共展示了BsonDocument.GetElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetMatchDocument

 /// <summary>
 /// 獲取Match
 /// </summary>
 /// <returns></returns>
 public BsonDocument GetMatchDocument()
 {
     BsonDocument Matchlist = new BsonDocument();
     foreach (ctlMatchItem item in this.Controls)
     {
         BsonDocument match = item.getMatchItem();
         if (match != null)
         {
             string MatchName = match.GetElement(0).Name;
             if (Matchlist.Contains(MatchName))
             {
                 BsonDocument AddMatch = match.GetElement(0).Value.AsBsonDocument;
                 Matchlist.GetElement(MatchName).Value.AsBsonDocument.Add(AddMatch);
             }
             else {
                 Matchlist.Add(match);
             }
         }
     }
     if (Matchlist.ElementCount > 0)
     {
         return new BsonDocument("$match", Matchlist);
     }
     else
     {
         return null;
     }
 }
開發者ID:Eddie0330,項目名稱:MagicMongoDBTool,代碼行數:32,代碼來源:MatchPanel.cs

示例2: TestBsonDocumentNoId

        public void TestBsonDocumentNoId()
        {
            _collection.RemoveAll();

            var document = new BsonDocument
            {
                { "A", 1 }
            };
            _collection.Save(document);
            Assert.Equal(2, document.ElementCount);
            Assert.Equal("_id", document.GetElement(0).Name);
            Assert.IsType<BsonObjectId>(document["_id"]);
            Assert.NotEqual(ObjectId.Empty, document["_id"].AsObjectId);
            Assert.Equal(1, _collection.Count());

            var id = document["_id"].AsObjectId;
            document["A"] = 2;
            _collection.Save(document);
            Assert.Equal(id, document["_id"].AsObjectId);
            Assert.Equal(1, _collection.Count());

            document = _collection.FindOneAs<BsonDocument>();
            Assert.Equal(2, document.ElementCount);
            Assert.Equal(id, document["_id"].AsObjectId);
            Assert.Equal(2, document["A"].AsInt32);
        }
開發者ID:RavenZZ,項目名稱:MDRelation,代碼行數:26,代碼來源:CSharp101Tests.cs

示例3: TestBsonDocumentBsonNullId

        public void TestBsonDocumentBsonNullId()
        {
            collection.RemoveAll();

            var document = new BsonDocument {
                { "_id", BsonNull.Value },
                { "A", 1 }
            };
            collection.Save(document);
            Assert.AreEqual(2, document.ElementCount);
            Assert.AreEqual("_id", document.GetElement(0).Name);
            Assert.IsInstanceOf<BsonObjectId>(document["_id"]);
            Assert.AreNotEqual(ObjectId.Empty, document["_id"].AsObjectId);
            Assert.AreEqual(1, collection.Count());

            var id = document["_id"].AsObjectId;
            document["A"] = 2;
            collection.Save(document);
            Assert.AreEqual(id, document["_id"].AsObjectId);
            Assert.AreEqual(1, collection.Count());

            document = collection.FindOneAs<BsonDocument>();
            Assert.AreEqual(2, document.ElementCount);
            Assert.AreEqual(id, document["_id"].AsObjectId);
            Assert.AreEqual(2, document["A"].AsInt32);
        }
開發者ID:jenrom,項目名稱:mongo-csharp-driver,代碼行數:26,代碼來源:CSharp101Tests.cs

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

示例5: GetMatchDocument

 /// <summary>
 ///     獲取Match
 /// </summary>
 /// <returns></returns>
 public BsonDocument GetMatchDocument()
 {
     var matchlist = new BsonDocument();
     foreach (Control item in Controls)
     {
         if (item.GetType().FullName == typeof(Button).FullName) continue;
         var match = ((CtlMatchItem)item).GetMatchItem();
         if (match != null)
         {
             var matchName = match.GetElement(0).Name;
             if (matchlist.Contains(matchName))
             {
                 var addMatch = match.GetElement(0).Value.AsBsonDocument;
                 matchlist.GetElement(matchName).Value.AsBsonDocument.AddRange(addMatch);
             }
             else
             {
                 matchlist.AddRange(match);
             }
         }
     }
     if (matchlist.ElementCount > 0)
     {
         return new BsonDocument("$match", matchlist);
     }
     return null;
 }
開發者ID:magicdict,項目名稱:MongoCola,代碼行數:31,代碼來源:ctlMatchPanel.cs

示例6: GetMatchDocument

 /// <summary>
 ///     獲取Match
 /// </summary>
 /// <returns></returns>
 public BsonDocument GetMatchDocument()
 {
     var matchlist = new BsonDocument();
     foreach (CtlMatchItem item in Controls)
     {
         var match = item.GetMatchItem();
         if (match != null)
         {
             var matchName = match.GetElement(0).Name;
             if (matchlist.Contains(matchName))
             {
                 var addMatch = match.GetElement(0).Value.AsBsonDocument;
                 matchlist.GetElement(matchName).Value.AsBsonDocument.AddRange(addMatch);
             }
             else
             {
                 matchlist.AddRange(match);
             }
         }
     }
     if (matchlist.ElementCount > 0)
     {
         return new BsonDocument("$match", matchlist);
     }
     return null;
 }
開發者ID:jango2015,項目名稱:MongoCola,代碼行數:30,代碼來源:MatchPanel.cs

示例7: DefaultImplementation

        // public static methods
        /// <summary>
        /// Default implementation of the CanCommandBeSentToSecondary delegate.
        /// </summary>
        /// <param name="document">The command.</param>
        /// <returns>True if the command can be sent to a secondary member of a replica set.</returns>
        public static bool DefaultImplementation(BsonDocument document)
        {
            if (document.ElementCount == 0)
            {
                return false;
            }

            var commandName = document.GetElement(0).Name;

            if (__secondaryOkCommands.Contains(commandName))
            {
                return true;
            }

            if (commandName.Equals("mapreduce", StringComparison.InvariantCultureIgnoreCase))
            {
                BsonValue outValue;
                if (document.TryGetValue("out", out outValue) && outValue.IsBsonDocument)
                {
                    return outValue.AsBsonDocument.Contains("inline");
                }
            }

            return false;
        }
開發者ID:Khosrow-Azizi,項目名稱:MasterExperimentV2,代碼行數:31,代碼來源:CanCommandBeSentToSecondary.cs

示例8: TestBsonDocumentEmptyGuid

        public void TestBsonDocumentEmptyGuid()
        {
            _collection.RemoveAll();

            var document = new BsonDocument
            {
                { "_id", Guid.Empty },
                { "A", 1 }
            };
            _collection.Save(document);
            Assert.AreEqual(2, document.ElementCount);
            Assert.AreEqual("_id", document.GetElement(0).Name);
            Assert.IsInstanceOf<BsonBinaryData>(document["_id"]);
            Assert.AreNotEqual(Guid.Empty, document["_id"].AsGuid);
            Assert.AreEqual(1, _collection.Count());

            var id = document["_id"].AsGuid;
            document["A"] = 2;
            _collection.Save(document);
            Assert.AreEqual(id, document["_id"].AsGuid);
            Assert.AreEqual(1, _collection.Count());

            document = _collection.FindOneAs<BsonDocument>();
            Assert.AreEqual(2, document.ElementCount);
            Assert.AreEqual(id, document["_id"].AsGuid);
            Assert.AreEqual(2, document["A"].AsInt32);
        }
開發者ID:moonreplace,項目名稱:mongo-csharp-driver,代碼行數:27,代碼來源:CSharp101Tests.cs

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

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

示例11: Execute

        public void Execute(BsonDocument doc)
        {
            var occurance = new BsonDocument(doc.GetElement("time"),
                                             doc.GetElement("details"));
            doc.Remove("time");
            doc.Remove("details");

            var query = Query.And(Query.EQ("token", doc["token"]),
                                  Query.EQ("hash", doc["hash"]));

            UpdateBuilder ub = new UpdateBuilder();
            ub.Push("occurances", occurance);
            ub.Set("token", doc["token"]);
            ub.Set("hash", doc["hash"]);
            ub.Set("level", doc["level"]);
            ub.Set("common", doc["common"]);
            ub.Set("lastTime", occurance["time"]);

            Events.Update(query, ub, UpdateFlags.Upsert);
        }
開發者ID:jpoehls,項目名稱:canary-dotnet,代碼行數:20,代碼來源:InsertEventAction.cs

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

示例13: UpdateDocument

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

            BsonDocument clientInfo = document.GetElement(ErrorRepository.FieldNames.ExceptionlessClientInfo).Value.AsBsonDocument;

            if (clientInfo.Contains("SubmissionMethod"))
                clientInfo.ChangeName("SubmissionMethod", ErrorRepository.FieldNames.SubmissionMethod);

            if (clientInfo.Contains(ErrorRepository.FieldNames.InstallDate)) {
                BsonValue installDateValue = clientInfo.GetElement(ErrorRepository.FieldNames.InstallDate).Value;
                if (installDateValue.IsBsonArray)
                    return;

                DateTime installDate = installDateValue.ToUniversalTime();
                clientInfo.AsBsonDocument.Set(ErrorRepository.FieldNames.InstallDate, new BsonArray(new BsonValue[] { new BsonInt64(installDate.Ticks), new BsonInt32(-360) }));
            }

            collection.Save(document);
        }
開發者ID:khoussem,項目名稱:Exceptionless,代碼行數:20,代碼來源:v1.0.10_Migration.cs

示例14: TestSetElementReplaceElement

 public void TestSetElementReplaceElement()
 {
     var document = new BsonDocument("x", 1);
     var element = new BsonElement("x", 2);
     document.SetElement(element);
     Assert.AreEqual(1, document.ElementCount);
     Assert.AreEqual("x", document.GetElement(0).Name);
     Assert.AreEqual(2, document["x"].AsInt32);
 }
開發者ID:jijamw,項目名稱:mongo-csharp-driver,代碼行數:9,代碼來源:BsonDocumentTests.cs

示例15: TestSetDocumentIdNewElement

 public void TestSetDocumentIdNewElement()
 {
     var document = new BsonDocument("x", 1);
     ((IBsonIdProvider)BsonDocumentSerializer.Instance).SetDocumentId(document, BsonValue.Create(2));
     Assert.AreEqual(2, document.ElementCount);
     Assert.AreEqual("_id", document.GetElement(0).Name);
     Assert.AreEqual(2, document["_id"].AsInt32);
 }
開發者ID:jijamw,項目名稱:mongo-csharp-driver,代碼行數:8,代碼來源:BsonDocumentTests.cs


注:本文中的BsonDocument.GetElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。