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


C# BsonDocument.Merge方法代码示例

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


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

示例1: TestMerge

 public void TestMerge() {
     var document = new BsonDocument();
     document.Merge(new BsonDocument("x", 1));
     Assert.AreEqual(1, document["x"].AsInt32);
     document.Merge(new BsonDocument("x", 2)); // don't overwriteExistingElements
     Assert.AreEqual(1, document["x"].AsInt32); // has old value
     document.Merge(new BsonDocument("x", 2), true); // overwriteExistingElements
     Assert.AreEqual(2, document["x"].AsInt32); // has new value
 }
开发者ID:kamiff,项目名称:mongo-csharp-driver,代码行数:9,代码来源:BsonDocumentTests.cs

示例2: CreateIndexDocument

        // methods
        internal BsonDocument CreateIndexDocument(SemanticVersion serverVersion)
        {
            Feature.Collation.ThrowIfNotSupported(serverVersion, _collation);

            var document = new BsonDocument
            {
                { "key", _keys },
                { "name", GetIndexName() },
                { "background", () => _background.Value, _background.HasValue },
                { "bits", () => _bits.Value, _bits.HasValue },
                { "bucketSize", () => _bucketSize.Value, _bucketSize.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null },
                { "default_language", () => _defaultLanguage, _defaultLanguage != null },
                { "expireAfterSeconds", () => _expireAfter.Value.TotalSeconds, _expireAfter.HasValue },
                { "language_override", () => _languageOverride, _languageOverride != null },
                { "max", () => _max.Value, _max.HasValue },
                { "min", () => _min.Value, _min.HasValue },
                { "partialFilterExpression", _partialFilterExpression, _partialFilterExpression != null },
                { "sparse", () => _sparse.Value, _sparse.HasValue },
                { "2dsphereIndexVersion", () => _sphereIndexVersion.Value, _sphereIndexVersion.HasValue },
                { "storageEngine", () => _storageEngine, _storageEngine != null },
                { "textIndexVersion", () => _textIndexVersion.Value, _textIndexVersion.HasValue },
                { "unique", () => _unique.Value, _unique.HasValue },
                { "v", () => _version.Value, _version.HasValue },
                { "weights", () => _weights, _weights != null }
            };

            if (_additionalOptions != null)
            {
                document.Merge(_additionalOptions, overwriteExistingElements: false);
            }
            return document;
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:34,代码来源:CreateIndexRequest.cs

示例3: MassageReply

        private BsonDocument MassageReply(string commandName, BsonDocument reply, BsonDocument expectedReply)
        {
            var massagedReply = (BsonDocument)DeepCopy(reply);
            switch (commandName)
            {
                case "find":
                case "getMore":
                    if (massagedReply.Contains("cursor") && massagedReply["cursor"]["id"] != 0L)
                    {
                        massagedReply["cursor"]["id"] = 42L;
                    }
                    break;
                case "killCursors":
                    massagedReply["cursorsUnknown"][0] = 42L;
                    break;
                case "delete":
                case "insert":
                case "update":
                    if (massagedReply.Contains("writeErrors"))
                    {
                        foreach (BsonDocument writeError in (BsonArray)massagedReply["writeErrors"])
                        {
                            writeError["code"] = 42;
                            writeError["errmsg"] = "";
                        }
                    }
                    break;
            }

            // add any fields in the actual reply into the expected reply that don't already exist
            expectedReply.Merge(reply, false);

            return massagedReply;
        }
开发者ID:ru-sh,项目名称:mongo-csharp-driver,代码行数:34,代码来源:TestRunner.cs

示例4: ProcessQueryReplyMessage

        private void ProcessQueryReplyMessage(CommandState state, ReplyMessage<RawBsonDocument> replyMessage, ConnectionId connectionId)
        {
            if (_succeededEvent != null)
            {
                BsonDocument reply;
                if (state.CommandName == "explain")
                {
                    reply = new BsonDocument("ok", 1);
                    reply.Merge(replyMessage.Documents[0]);
                }
                else
                {
                    var batchName = state.CommandName == "find" ? "firstBatch" : "nextBatch";
                    reply = new BsonDocument
                    {
                        { "cursor", new BsonDocument
                                    {
                                        { "id", replyMessage.CursorId },
                                        { "ns", state.QueryNamespace.FullName },
                                        { batchName, new BsonArray(replyMessage.Documents) }
                                    }},
                        { "ok", 1 }
                    };
                }

                _succeededEvent(new CommandSucceededEvent(
                    state.CommandName,
                    reply,
                    state.OperationId,
                    replyMessage.ResponseTo,
                    connectionId,
                    state.Stopwatch.Elapsed));
            }
        }
开发者ID:joeenzminger,项目名称:mongo-csharp-driver,代码行数:34,代码来源:CommandEventHelper.cs

示例5: TestMergeNull

 public void TestMergeNull()
 {
     var document = new BsonDocument();
     Assert.Throws<ArgumentNullException>(() => { document.Merge(null); });
 }
开发者ID:jijamw,项目名称:mongo-csharp-driver,代码行数:5,代码来源:BsonDocumentTests.cs

示例6: ToWriteConcernResult

        // private methods
        private WriteConcernResult ToWriteConcernResult(BulkWriteResult bulkWriteResult, BulkWriteException bulkWriteException)
        {
            if (!bulkWriteResult.IsAcknowledged)
            {
                return null;
            }

            // don't include InsertedCount in getLastErrorResponse
            var documentsAffectedCount =
                bulkWriteResult.DeletedCount +
                bulkWriteResult.MatchedCount +
                bulkWriteResult.Upserts.Count;

            var isUpdate = bulkWriteResult.ProcessedRequests.Any(r => r.RequestType == WriteRequestType.Update);

            var updatedExisting = false;
            BulkWriteUpsert upsert = null;
            if (isUpdate)
            {
                upsert = bulkWriteResult.Upserts.LastOrDefault();
                updatedExisting = documentsAffectedCount > 0 && upsert == null;
            }

            var code = 0;
            string message = null;
            BsonDocument details = null;
            if (bulkWriteException != null)
            {
                var lastWriteError = bulkWriteException.WriteErrors.LastOrDefault();
                var writeConcernError = bulkWriteException.WriteConcernError;

                code = 8; // UnknownError
                if (lastWriteError != null)
                {
                    code = lastWriteError.Code;
                    message = lastWriteError.Message;
                    details = lastWriteError.Details;
                }
                else if (writeConcernError != null)
                {
                    code = writeConcernError.Code;
                    message = writeConcernError.Message;
                    details = writeConcernError.Details;
                }
            }

            var getLastErrorResponse = new BsonDocument
            {
                { "ok", 1 },
                { "code", code, code != 0 },
                { "err", message, message != null },
                { "n", documentsAffectedCount },
                { "updatedExisting", updatedExisting, isUpdate },
                { "upserted", () => upsert.Id, isUpdate && upsert != null },
            };
            getLastErrorResponse.Merge(details, false); // don't overwrite existing elements

            return new WriteConcernResult(getLastErrorResponse);
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:60,代码来源:BulkWriteResultConverter.cs

示例7: CreateSubject

        private GridFSFileInfo CreateSubject(
             IEnumerable<string> aliases = null,
            int? chunkSizeBytes = null,
            string contentType = null,
            BsonDocument extraElements = null,
            string filename = null,
            BsonValue idAsBsonValue = null,
            long? length = null,
            string md5 = null,
            BsonDocument metadata = null,
            DateTime? uploadDateTime = null)
        {
            var backingDocument = new BsonDocument
            {
                { "_id", idAsBsonValue ?? (BsonValue)ObjectId.GenerateNewId() },
                { "length", length ?? 0 },
                { "chunkSize", chunkSizeBytes ?? 255 * 1024 },
                { "uploadDate", uploadDateTime ?? DateTime.UtcNow },
                { "md5", md5 ?? "md5" },
                { "filename", filename ?? "filename" },
                { "contentType", contentType, contentType != null },
                { "aliases", () => new BsonArray(aliases.Select(a => new BsonString(a))), aliases != null },
                { "metadata", metadata, metadata != null }
            };
            if (extraElements != null)
            {
                backingDocument.Merge(extraElements, overwriteExistingElements: false);
            }

            return new GridFSFileInfo(backingDocument);
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:31,代码来源:GridFSFileInfoTests.cs


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