当前位置: 首页>>代码示例>>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;未经允许,请勿转载。