// protected methods /// <inheritdoc /> protected override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, int attempt, long?transactionNumber) { var serverVersion = connectionDescription.ServerVersion; if (!Feature.ArrayFilters.IsSupported(serverVersion)) { if (_updates.Items.Skip(_updates.Offset).Take(_updates.Count).Any(u => u.ArrayFilters != null)) { throw new NotSupportedException($"Server version {serverVersion} does not support arrayFilters."); } } if (Feature.HintForUpdateAndReplaceOperations.DriverMustThrowIfNotSupported(serverVersion) || (WriteConcern != null && !WriteConcern.IsAcknowledged)) { if (_updates.Items.Skip(_updates.Offset).Take(_updates.Count).Any(u => u.Hint != null)) { throw new NotSupportedException($"Server version {serverVersion} does not support hints."); } } var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern); return(new BsonDocument { { "update", _collectionNamespace.CollectionName }, { "ordered", IsOrdered }, { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue }, { "writeConcern", writeConcern, writeConcern != null }, { "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue } }); }
// methods internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, long?transactionNumber) { var maxWireVersion = connectionDescription.MaxWireVersion; if (Feature.HintForFindAndModifyFeature.DriverMustThrowIfNotSupported(maxWireVersion) || (WriteConcern != null && !WriteConcern.IsAcknowledged)) { if (_hint != null) { throw new NotSupportedException($"Server version {WireVersion.GetServerVersionForErrorMessage(maxWireVersion)} does not support hints."); } } var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern); return(new BsonDocument { { "findAndModify", CollectionNamespace.CollectionName }, { "query", _filter }, { "update", _update }, { "new", true, _returnDocument == ReturnDocument.After }, { "sort", _sort, _sort != null }, { "fields", _projection, _projection != null }, { "upsert", true, _isUpsert }, { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue }, { "writeConcern", writeConcern, writeConcern != null }, { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue }, { "collation", () => Collation.ToBsonDocument(), Collation != null }, { "comment", Comment, Comment != null }, { "hint", _hint, _hint != null }, { "arrayFilters", () => new BsonArray(_arrayFilters), _arrayFilters != null }, { "txnNumber", () => transactionNumber, transactionNumber.HasValue }, { "let", _let, _let != null } }); }
// methods internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription) { var flags = GetFlags(); var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern); return(new BsonDocument { { "create", _collectionNamespace.CollectionName }, { "capped", () => _capped.Value, _capped.HasValue }, { "autoIndexId", () => _autoIndexId.Value, _autoIndexId.HasValue }, { "size", () => _maxSize.Value, _maxSize.HasValue }, { "max", () => _maxDocuments.Value, _maxDocuments.HasValue }, { "flags", () => (int)flags.Value, flags.HasValue }, { "storageEngine", _storageEngine, _storageEngine != null }, { "indexOptionDefaults", _indexOptionDefaults, _indexOptionDefaults != null }, { "validator", _validator, _validator != null }, { "validationAction", () => _validationAction.Value.ToString().ToLowerInvariant(), _validationAction.HasValue }, { "validationLevel", () => _validationLevel.Value.ToString().ToLowerInvariant(), _validationLevel.HasValue }, { "collation", () => _collation.ToBsonDocument(), _collation != null }, { "comment", _comment, _comment != null }, { "writeConcern", writeConcern, writeConcern != null }, { "expireAfterSeconds", () => _expireAfter.Value.TotalSeconds, _expireAfter.HasValue }, { "timeseries", () => _timeSeriesOptions.ToBsonDocument(), _timeSeriesOptions != null } }); }
// methods internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, long?transactionNumber) { var serverVersion = connectionDescription.ServerVersion; if (Feature.HintForFindAndModifyFeature.DriverMustThrowIfNotSupported(serverVersion) || (WriteConcern != null && !WriteConcern.IsAcknowledged)) { if (_hint != null) { throw new NotSupportedException($"Server version {serverVersion} does not support hints."); } } var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern); return(new BsonDocument { { "findAndModify", CollectionNamespace.CollectionName }, { "query", _filter }, { "remove", true }, { "sort", _sort, _sort != null }, { "fields", _projection, _projection != null }, { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue }, { "writeConcern", writeConcern, writeConcern != null }, { "collation", () => Collation.ToBsonDocument(), Collation != null }, { "hint", _hint, _hint != null }, { "txnNumber", () => transactionNumber, transactionNumber.HasValue } }); }
// private methods internal BsonDocument CreateCommand(ICoreSessionHandle session) { var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern); return(new BsonDocument { { "dropDatabase", 1 }, { "writeConcern", writeConcern, writeConcern != null } }); }
// private methods internal BsonDocument CreateCommand(ICoreSessionHandle session) { var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern); return(new BsonDocument { { "drop", _collectionNamespace.CollectionName }, { "writeConcern", writeConcern, writeConcern != null } }); }
public void GetWriteConcernForWriteCommand_should_return_expected_result( bool isInTransaction, string writeConcernJson, string expectedResult) { var session = CreateSession(isInTransaction: isInTransaction); var writeConcern = writeConcernJson == null ? null : WriteConcern.FromBsonDocument(BsonDocument.Parse(writeConcernJson)); var result = WriteConcernHelper.GetEffectiveWriteConcern(session, writeConcern); result.Should().Be(expectedResult); }
// methods internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription) { var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern); return(new BsonDocument { { "renameCollection", _collectionNamespace.FullName }, { "to", _newCollectionNamespace.FullName }, { "dropTarget", () => _dropTarget.Value, _dropTarget.HasValue }, { "writeConcern", writeConcern, writeConcern != null } }); }
// methods internal BsonDocument CreateCommand(ICoreSessionHandle session) { var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern); return(new BsonDocument { { "dropIndexes", _collectionNamespace.CollectionName }, { "index", _indexName }, { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue }, { "writeConcern", writeConcern, writeConcern != null } }); }
// private methods internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription) { var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern); return(new BsonDocument { { "create", _viewName }, { "viewOn", _viewOn }, { "pipeline", new BsonArray(_pipeline) }, { "collation", () => _collation.ToBsonDocument(), _collation != null }, { "writeConcern", writeConcern, writeConcern != null } }); }
// protected methods /// <inheritdoc /> protected override BsonDocument CreateCommand(ICoreSessionHandle session, int attempt, long?transactionNumber) { var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern); return(new BsonDocument { { "insert", _collectionNamespace.CollectionName }, { "ordered", IsOrdered }, { "bypassDocumentValidation", () => _bypassDocumentValidation, _bypassDocumentValidation.HasValue }, { "writeConcern", writeConcern, writeConcern != null }, { "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue } }); }
// methods /// <inheritdoc/> protected internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription) { var command = base.CreateCommand(session, connectionDescription); if (_bypassDocumentValidation.HasValue) { command.Add("bypassDocumentValidation", _bypassDocumentValidation.Value); } var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern); if (writeConcern != null) { command.Add("writeConcern", writeConcern.ToBsonDocument()); } return(command); }
// protected methods /// <inheritdoc /> protected override BsonDocument CreateCommand(ICoreSessionHandle session, int attempt, long?transactionNumber) { if (WriteConcern != null && !WriteConcern.IsAcknowledged) { if (_deletes.Items.Skip(_deletes.Offset).Take(_deletes.Count).Any(u => u.Hint != null)) { throw new NotSupportedException("Hint is not supported for unacknowledged writes."); } } var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern); return(new BsonDocument { { "delete", _collectionNamespace.CollectionName }, { "ordered", IsOrdered }, { "writeConcern", writeConcern, writeConcern != null }, { "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue }, { "let", _let, _let != null } }); }
internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription) { var readConcern = _readConcern != null ? ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, _readConcern) : null; var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern); return(new BsonDocument { { "aggregate", _collectionNamespace == null ? (BsonValue)1 : _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(_pipeline) }, { "allowDiskUse", () => _allowDiskUse.Value, _allowDiskUse.HasValue }, { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue }, { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue }, { "collation", () => _collation.ToBsonDocument(), _collation != null }, { "readConcern", readConcern, readConcern != null }, { "writeConcern", writeConcern, writeConcern != null }, { "cursor", new BsonDocument() }, { "hint", () => _hint, _hint != null }, { "let", () => _let, _let != null }, { "comment", () => _comment, _comment != null } }); }