diff --git a/src/operations/delete.ts b/src/operations/delete.ts index 9f97f487be9..d6f6de4f187 100644 --- a/src/operations/delete.ts +++ b/src/operations/delete.ts @@ -3,7 +3,7 @@ import { type Connection } from '../cmap/connection'; import { MongoDBResponse } from '../cmap/wire_protocol/responses'; import { MongoCompatibilityError, MongoServerError } from '../error'; import type { ClientSession } from '../sessions'; -import { type MongoDBCollectionNamespace, type MongoDBNamespace } from '../utils'; +import { maxWireVersion, type MongoDBCollectionNamespace, type MongoDBNamespace } from '../utils'; import { type WriteConcernOptions } from '../write_concern'; import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects, type Hint } from './operation'; @@ -65,7 +65,7 @@ export class DeleteOperation extends CommandOperation { return this.statements.every(op => (op.limit != null ? op.limit > 0 : true)); } - override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document { + override buildCommandDocument(connection: Connection, _session?: ClientSession): Document { const options = this.options; const ordered = typeof options.ordered === 'boolean' ? options.ordered : true; @@ -86,10 +86,11 @@ export class DeleteOperation extends CommandOperation { } const unacknowledgedWrite = this.writeConcern && this.writeConcern.w === 0; - if (unacknowledgedWrite) { + if (unacknowledgedWrite && maxWireVersion(connection) < 9) { if (this.statements.find((o: Document) => o.hint)) { - // TODO(NODE-3541): fix error for hint with unacknowledged writes - throw new MongoCompatibilityError(`hint is not supported with unacknowledged writes`); + throw new MongoCompatibilityError( + `hint for the delete command is only supported on MongoDB 4.4+` + ); } } diff --git a/src/operations/find_and_modify.ts b/src/operations/find_and_modify.ts index b8c573e3adc..00c5e6530c3 100644 --- a/src/operations/find_and_modify.ts +++ b/src/operations/find_and_modify.ts @@ -6,7 +6,7 @@ import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error'; import { ReadPreference } from '../read_preference'; import type { ClientSession } from '../sessions'; import { formatSort, type Sort, type SortForCmd } from '../sort'; -import { decorateWithCollation, hasAtomicOperators } from '../utils'; +import { decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils'; import { type WriteConcern, type WriteConcernSettings } from '../write_concern'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -146,7 +146,7 @@ export class FindAndModifyOperation extends CommandOperation { } override buildCommandDocument( - _connection: Connection, + connection: Connection, _session?: ClientSession ): Document & FindAndModifyCmdBase { const options = this.options; @@ -192,9 +192,9 @@ export class FindAndModifyOperation extends CommandOperation { if (options.hint) { const unacknowledgedWrite = this.writeConcern?.w === 0; - if (unacknowledgedWrite) { + if (unacknowledgedWrite && maxWireVersion(connection) < 9) { throw new MongoCompatibilityError( - 'The current topology does not support a hint on findAndModify commands' + 'hint for the findAndModify command is only supported on MongoDB 4.4+' ); } diff --git a/src/operations/update.ts b/src/operations/update.ts index 089390fcf73..c09001ba2f8 100644 --- a/src/operations/update.ts +++ b/src/operations/update.ts @@ -1,7 +1,7 @@ import type { Document } from '../bson'; import { type Connection } from '../cmap/connection'; import { MongoDBResponse } from '../cmap/wire_protocol/responses'; -import { MongoCompatibilityError, MongoInvalidArgumentError, MongoServerError } from '../error'; +import { MongoInvalidArgumentError, MongoServerError } from '../error'; import type { InferIdType } from '../mongo_types'; import type { ClientSession } from '../sessions'; import { formatSort, type Sort, type SortForCmd } from '../sort'; @@ -121,14 +121,6 @@ export class UpdateOperation extends CommandOperation { command.comment = options.comment; } - const unacknowledgedWrite = this.writeConcern?.w === 0; - if (unacknowledgedWrite) { - if (this.statements.find((o: Document) => o.hint)) { - // TODO(NODE-3541): fix error for hint with unacknowledged writes - throw new MongoCompatibilityError(`hint is not supported with unacknowledged writes`); - } - } - return command; } } diff --git a/test/integration/crud/crud.spec.test.ts b/test/integration/crud/crud.spec.test.ts index 243b8c8e614..a49df8314ea 100644 --- a/test/integration/crud/crud.spec.test.ts +++ b/test/integration/crud/crud.spec.test.ts @@ -3,35 +3,6 @@ import * as path from 'path'; import { loadSpecTests } from '../../spec/index'; import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; -const unacknowledgedHintTests = [ - 'Unacknowledged updateOne with hint document on 4.2+ server', - 'Unacknowledged updateOne with hint string on 4.2+ server', - 'Unacknowledged updateMany with hint document on 4.2+ server', - 'Unacknowledged updateMany with hint string on 4.2+ server', - 'Unacknowledged replaceOne with hint document on 4.2+ server', - 'Unacknowledged replaceOne with hint string on 4.2+ server', - 'Unacknowledged updateOne with hint document on 4.2+ server', - 'Unacknowledged updateOne with hint string on 4.2+ server', - 'Unacknowledged updateMany with hint document on 4.2+ server', - 'Unacknowledged updateMany with hint string on 4.2+ server', - 'Unacknowledged replaceOne with hint document on 4.2+ server', - 'Unacknowledged replaceOne with hint string on 4.2+ server', - 'Unacknowledged findOneAndUpdate with hint document on 4.4+ server', - 'Unacknowledged findOneAndUpdate with hint string on 4.4+ server', - 'Unacknowledged findOneAndReplace with hint document on 4.4+ server', - 'Unacknowledged findOneAndReplace with hint string on 4.4+ server', - 'Unacknowledged findOneAndDelete with hint document on 4.4+ server', - 'Unacknowledged findOneAndDelete with hint string on 4.4+ server', - 'Unacknowledged deleteOne with hint document on 4.4+ server', - 'Unacknowledged deleteOne with hint string on 4.4+ server', - 'Unacknowledged deleteMany with hint document on 4.4+ server', - 'Unacknowledged deleteMany with hint string on 4.4+ server', - 'Unacknowledged deleteOne with hint document on 4.4+ server', - 'Unacknowledged deleteOne with hint string on 4.4+ server', - 'Unacknowledged deleteMany with hint document on 4.4+ server', - 'Unacknowledged deleteMany with hint string on 4.4+ server' -]; - const loadBalancedCollationTests = [ 'FindOneAndUpdate when many documents match with collation returning the document before modification', 'FindOneAndReplace when one document matches with collation returning the document after modification', @@ -70,13 +41,10 @@ describe('CRUD unified', function () { runUnifiedSuite( loadSpecTests(path.join('crud', 'unified')), ({ description }, { isLoadBalanced }) => { - return unacknowledgedHintTests.includes(description) - ? `TODO(NODE-3541)` - : isLoadBalanced && loadBalancedCollationTests.includes(description) - ? `TODO(NODE-6280): fix collation for find and modify commands on load balanced mode` - : description in unimplementedCrudTests - ? unimplementedCrudTests[description] - : false; + if (isLoadBalanced && loadBalancedCollationTests.includes(description)) { + return `TODO(NODE-6280): fix collation for find and modify commands on load balanced mode`; + } + return unimplementedCrudTests[description] ?? false; } ); });