Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/operations/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -65,7 +65,7 @@ export class DeleteOperation extends CommandOperation<Document> {
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;
Expand All @@ -86,10 +86,11 @@ export class DeleteOperation extends CommandOperation<Document> {
}

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+`
);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/operations/find_and_modify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -146,7 +146,7 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
}

override buildCommandDocument(
_connection: Connection,
connection: Connection,
_session?: ClientSession
): Document & FindAndModifyCmdBase {
const options = this.options;
Expand Down Expand Up @@ -192,9 +192,9 @@ export class FindAndModifyOperation extends CommandOperation<Document> {

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+'
);
}

Expand Down
10 changes: 1 addition & 9 deletions src/operations/update.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -121,14 +121,6 @@ export class UpdateOperation extends CommandOperation<Document> {
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;
}
}
Expand Down
40 changes: 4 additions & 36 deletions test/integration/crud/crud.spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
);
});