Exemple #1
0
        private BsonDocument CreateWriteCommand(BatchSerializer batchSerializer, BatchableSource <WriteRequest> requestSource)
        {
            var batchWrapper = new BsonDocumentWrapper(requestSource, batchSerializer);

            var writeConcern = _writeConcern.ToBsonDocument();

            if (writeConcern.ElementCount == 0)
            {
                writeConcern = null; // omit field if writeConcern is { }
            }

            return(new BsonDocument
            {
                { CommandName, _collectionNamespace.CollectionName },
                { "writeConcern", writeConcern, writeConcern != null },
                { "ordered", _isOrdered },
                { RequestsElementName, new BsonArray {
                      batchWrapper
                  } }
            });
        }
        // private methods
        private CommandDocument CreateWriteCommand(BatchSerializer batchSerializer, Batch <WriteRequest> batch)
        {
            var batchWrapper = new BsonDocumentWrapper(batch, batchSerializer, false);

            var writeConcern = _args.WriteConcern.ToBsonDocument();

            if (writeConcern.ElementCount == 0)
            {
                writeConcern = null; // omit field if writeConcern is { }
            }

            return(new CommandDocument
            {
                { CommandName, _args.CollectionName },
                { "writeConcern", writeConcern, writeConcern != null },
                { "ordered", _args.IsOrdered },
                { RequestsElementName, new BsonArray {
                      batchWrapper
                  } }
            });
        }
        private BsonDocument CreateWriteCommand(BatchSerializer batchSerializer, BatchableSource <WriteRequest> requestSource, SemanticVersion serverVersion)
        {
            var batchWrapper = new BsonDocumentWrapper(requestSource, batchSerializer);

            WriteConcern effectiveWriteConcern = _writeConcern;

            if (!effectiveWriteConcern.IsAcknowledged && _isOrdered)
            {
                effectiveWriteConcern = WriteConcern.W1; // ignore the server's default, whatever it may be.
            }

            return(new BsonDocument
            {
                { CommandName, _collectionNamespace.CollectionName },
                { "writeConcern", () => effectiveWriteConcern.ToBsonDocument(), !effectiveWriteConcern.IsServerDefault },
                { "ordered", _isOrdered },
                { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue&& Feature.BypassDocumentValidation.IsSupported(serverVersion) },
                { RequestsElementName, new BsonArray {
                      batchWrapper
                  } }                                                   // should be last
            });
        }
        // private methods
        private CommandDocument CreateWriteCommand(BatchSerializer batchSerializer, Batch<WriteRequest> batch)
        {
            var wrappedActualType = batch.GetType();
            var batchWrapper = new BsonDocumentWrapper(wrappedActualType, batch, batchSerializer, null, false);

            var writeConcern = _args.WriteConcern.ToBsonDocument();
            if (writeConcern.ElementCount == 0)
            {
                writeConcern = null; // omit field if writeConcern is { }
            }

            return new CommandDocument
            {
                { CommandName, _args.CollectionName },
                { "writeConcern", writeConcern, writeConcern != null },
                { "ordered", _args.IsOrdered },
                { RequestsElementName, new BsonArray { batchWrapper } }
            };
        }