diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 211c802c182..26c0d750d9c 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -20,7 +20,6 @@ import type { Topology } from '../sdam/topology'; import { type Sort } from '../sort'; import { TimeoutContext } from '../timeout'; import { - applyRetryableWrites, getTopology, hasAtomicOperators, maybeAddIdToDocuments, @@ -527,15 +526,15 @@ async function executeCommands( finalOptions.checkKeys = false; } - if (finalOptions.retryWrites) { + if (bulkOperation.retryWrites) { if (isUpdateBatch(batch)) { - finalOptions.retryWrites = - finalOptions.retryWrites && !batch.operations.some(op => op.multi); + bulkOperation.retryWrites = + bulkOperation.retryWrites && !batch.operations.some(op => op.multi); } if (isDeleteBatch(batch)) { - finalOptions.retryWrites = - finalOptions.retryWrites && !batch.operations.some(op => op.limit === 0); + bulkOperation.retryWrites = + bulkOperation.retryWrites && !batch.operations.some(op => op.limit === 0); } } @@ -859,6 +858,8 @@ export abstract class BulkOperationBase { s: BulkOperationPrivate; operationId?: number; private collection: Collection; + /** @internal */ + retryWrites?: boolean; /** * Create a new OrderedBulkOperation or UnorderedBulkOperation instance @@ -866,6 +867,7 @@ export abstract class BulkOperationBase { */ constructor(collection: Collection, options: BulkWriteOptions, isOrdered: boolean) { this.collection = collection; + this.retryWrites = collection.db.options?.retryWrites; // determine whether bulkOperation is ordered or unordered this.isOrdered = isOrdered; @@ -898,10 +900,6 @@ export abstract class BulkOperationBase { // + 1 bytes for null terminator const maxKeySize = (maxWriteBatchSize - 1).toString(10).length + 2; - // Final options for retryable writes - let finalOptions = Object.assign({}, options); - finalOptions = applyRetryableWrites(finalOptions, collection.db); - // Final results const bulkResult: BulkResult = { ok: 1, @@ -943,7 +941,7 @@ export abstract class BulkOperationBase { // Topology topology, // Options - options: finalOptions, + options: options, // BSON options bsonOptions: resolveBSONOptions(options), // Current operation diff --git a/src/change_stream.ts b/src/change_stream.ts index 1076b2f66bb..26833124120 100644 --- a/src/change_stream.ts +++ b/src/change_stream.ts @@ -17,8 +17,7 @@ import { import { MongoClient } from './mongo_client'; import { type InferIdType, TypedEventEmitter } from './mongo_types'; import type { AggregateOptions } from './operations/aggregate'; -import type { CollationOptions, OperationParent } from './operations/command'; -import type { ReadPreference } from './read_preference'; +import type { OperationParent } from './operations/command'; import { type AsyncDisposable, configureResourceManagement } from './resource_management'; import type { ServerSessionId } from './sessions'; import { CSOTTimeoutContext, type TimeoutContext } from './timeout'; @@ -45,21 +44,6 @@ const NO_RESUME_TOKEN_ERROR = 'A change stream document has been received that lacks a resume token (_id).'; const CHANGESTREAM_CLOSED_ERROR = 'ChangeStream is closed'; -/** - * @public - * @deprecated Please use the ChangeStreamCursorOptions type instead. - */ -export interface ResumeOptions { - startAtOperationTime?: Timestamp; - batchSize?: number; - maxAwaitTimeMS?: number; - collation?: CollationOptions; - readPreference?: ReadPreference; - resumeAfter?: ResumeToken; - startAfter?: ResumeToken; - fullDocument?: string; -} - /** * Represents the logical starting point for a new ChangeStream or resuming a ChangeStream on the server. * @see https://www.mongodb.com/docs/manual/changeStreams/#std-label-change-stream-resume diff --git a/src/cmap/connection.ts b/src/cmap/connection.ts index e235c6e2393..d2d7f8bf12e 100644 --- a/src/cmap/connection.ts +++ b/src/cmap/connection.ts @@ -138,6 +138,7 @@ export interface ConnectionOptions tls: boolean; noDelay?: boolean; socketTimeoutMS?: number; + /** @internal */ cancellationToken?: CancellationToken; metadata: ClientMetadata; /** @internal */ diff --git a/src/cmap/connection_pool.ts b/src/cmap/connection_pool.ts index 946b568cd0a..a4d931518fb 100644 --- a/src/cmap/connection_pool.ts +++ b/src/cmap/connection_pool.ts @@ -97,15 +97,6 @@ export const PoolState = Object.freeze({ type PoolState = (typeof PoolState)[keyof typeof PoolState]; -/** - * @public - * @deprecated This interface is deprecated and will be removed in a future release as it is not used - * in the driver - */ -export interface CloseOptions { - force?: boolean; -} - /** @public */ export type ConnectionPoolEvents = { connectionPoolCreated(event: ConnectionPoolCreatedEvent): void; diff --git a/src/cmap/handshake/client_metadata.ts b/src/cmap/handshake/client_metadata.ts index 295e1af078a..c8737d36aef 100644 --- a/src/cmap/handshake/client_metadata.ts +++ b/src/cmap/handshake/client_metadata.ts @@ -56,19 +56,6 @@ export interface ClientMetadata { }; } -/** - * @public - * @deprecated This interface will be made internal in the next major release. - */ -export interface ClientMetadataOptions { - driverInfo?: { - name?: string; - version?: string; - platform?: string; - }; - appName?: string; -} - /** @internal */ export class LimitedSizeDocument { private document = new Map(); diff --git a/src/cmap/wire_protocol/constants.ts b/src/cmap/wire_protocol/constants.ts index 60ebf6d68f8..3265ca1a03d 100644 --- a/src/cmap/wire_protocol/constants.ts +++ b/src/cmap/wire_protocol/constants.ts @@ -1,5 +1,7 @@ export const MIN_SUPPORTED_SERVER_VERSION = '4.2'; export const MAX_SUPPORTED_SERVER_VERSION = '8.2'; +export const MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION = 13; +export const MIN_SUPPORTED_SNAPSHOT_READS_SERVER_VERSION = '5.0'; export const MIN_SUPPORTED_WIRE_VERSION = 8; export const MAX_SUPPORTED_WIRE_VERSION = 27; export const MIN_SUPPORTED_QE_WIRE_VERSION = 21; diff --git a/src/collection.ts b/src/collection.ts index f693bdf5a47..e3a52057363 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -546,7 +546,7 @@ export class Collection { // Explicitly set the limit to 1 and singleBatch to true for all commands, per the spec. // noCursorTimeout must be unset as well as batchSize. // See: https://github.com/mongodb/specifications/blob/master/source/crud/crud.md#findone-api-details - const { batchSize: _batchSize, noCursorTimeout: _noCursorTimeout, ...opts } = options; + const { ...opts } = options; opts.singleBatch = true; const cursor = this.find(filter, opts).limit(1); const result = await cursor.next(); diff --git a/src/connection_string.ts b/src/connection_string.ts index 97b7d4d62cc..6da2891f643 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -1283,16 +1283,6 @@ export const OPTIONS = { secureProtocol: { type: 'any' }, index: { type: 'any' }, // Legacy options from v3 era - useNewUrlParser: { - type: 'boolean', - deprecated: - 'useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' - } as OptionDescriptor, - useUnifiedTopology: { - type: 'boolean', - deprecated: - 'useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' - } as OptionDescriptor, __skipPingOnConnect: { type: 'boolean' } } as Record; diff --git a/src/gridfs/download.ts b/src/gridfs/download.ts index 022bcf94449..563678c3175 100644 --- a/src/gridfs/download.ts +++ b/src/gridfs/download.ts @@ -53,10 +53,6 @@ export interface GridFSFile { filename: string; metadata?: Document; uploadDate: Date; - /** @deprecated Will be removed in the next major version. */ - contentType?: string; - /** @deprecated Will be removed in the next major version. */ - aliases?: string[]; } /** @internal */ diff --git a/src/gridfs/upload.ts b/src/gridfs/upload.ts index 02317264c7c..bd1449da4a1 100644 --- a/src/gridfs/upload.ts +++ b/src/gridfs/upload.ts @@ -32,16 +32,6 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions { id?: ObjectId; /** Object to store in the file document's `metadata` field */ metadata?: Document; - /** - * String to store in the file document's `contentType` field. - * @deprecated Will be removed in the next major version. Add a contentType field to the metadata document instead. - */ - contentType?: string; - /** - * Array of strings to store in the file document's `aliases` field. - * @deprecated Will be removed in the next major version. Add an aliases field to the metadata document instead. - */ - aliases?: string[]; /** * @experimental * Specifies the time an operation will run until it throws a timeout error @@ -305,8 +295,6 @@ function checkDone(stream: GridFSBucketWriteStream, callback: Callback): void { stream.length, stream.chunkSizeBytes, stream.filename, - stream.options.contentType, - stream.options.aliases, stream.options.metadata ); @@ -402,8 +390,6 @@ function createFilesDoc( length: number, chunkSize: number, filename: string, - contentType?: string, - aliases?: string[], metadata?: Document ): GridFSFile { const ret: GridFSFile = { @@ -414,14 +400,6 @@ function createFilesDoc( filename }; - if (contentType) { - ret.contentType = contentType; - } - - if (aliases) { - ret.aliases = aliases; - } - if (metadata) { ret.metadata = metadata; } diff --git a/src/index.ts b/src/index.ts index e02dbf37538..13bfe15642b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -224,7 +224,6 @@ export type { ChangeStreamSplitEvent, ChangeStreamUpdateDocument, OperationTime, - ResumeOptions, ResumeToken, UpdateDescription } from './change_stream'; @@ -307,7 +306,6 @@ export type { ProxyOptions } from './cmap/connection'; export type { - CloseOptions, ConnectionPool, ConnectionPoolEvents, ConnectionPoolOptions, @@ -315,7 +313,7 @@ export type { WaitQueueMember, WithConnectionCallback } from './cmap/connection_pool'; -export type { ClientMetadata, ClientMetadataOptions } from './cmap/handshake/client_metadata'; +export type { ClientMetadata } from './cmap/handshake/client_metadata'; export type { ConnectionPoolMetrics } from './cmap/metrics'; export type { StreamDescription, StreamDescriptionOptions } from './cmap/stream_description'; export type { CompressorName } from './cmap/wire_protocol/compression'; @@ -598,7 +596,6 @@ export type { SrvPoller, SrvPollerEvents, SrvPollerOptions } from './sdam/srv_po export type { ConnectOptions, SelectServerOptions, - ServerCapabilities, ServerSelectionCallback, ServerSelectionRequest, Topology, diff --git a/src/mongo_types.ts b/src/mongo_types.ts index e96204931f3..3c56585a731 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -473,8 +473,7 @@ export class TypedEventEmitter extends EventEm } /** - * @public - * @deprecated Will be removed in favor of `AbortSignal` in the next major release. + * @internal */ export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> { constructor(...args: any[]) { diff --git a/src/operations/command.ts b/src/operations/command.ts index b08f83e1996..ab0bf1e1d9f 100644 --- a/src/operations/command.ts +++ b/src/operations/command.ts @@ -53,13 +53,6 @@ export interface CommandOperationOptions * In server versions 4.4 and above, 'comment' can be any valid BSON type. */ comment?: unknown; - /** - * @deprecated - * This option is deprecated and will be removed in a future release as it is not used - * in the driver. Use MongoClientOptions or connection string parameters instead. - * */ - retryWrites?: boolean; - // Admin command overrides. dbName?: string; authdb?: string; diff --git a/src/operations/create_collection.ts b/src/operations/create_collection.ts index 888f1077390..15733c91176 100644 --- a/src/operations/create_collection.ts +++ b/src/operations/create_collection.ts @@ -23,7 +23,6 @@ const ILLEGAL_COMMAND_FIELDS = new Set([ 'timeoutMS', 'j', 'fsync', - 'autoIndexId', 'pkFactory', 'raw', 'readPreference', @@ -68,8 +67,6 @@ export interface ClusteredCollectionOptions extends Document { export interface CreateCollectionOptions extends Omit { /** Create a capped collection */ capped?: boolean; - /** @deprecated Create an index on the _id field of the document. This option is deprecated in MongoDB 3.2+ and will be removed once no longer supported by the server. */ - autoIndexId?: boolean; /** The size of the capped collection in bytes */ size?: number; /** The maximum number of documents in the capped collection */ diff --git a/src/operations/execute_operation.ts b/src/operations/execute_operation.ts index 61d943e6424..d833623d148 100644 --- a/src/operations/execute_operation.ts +++ b/src/operations/execute_operation.ts @@ -1,3 +1,4 @@ +import { MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION } from '../cmap/wire_protocol/constants'; import { isRetryableReadError, isRetryableWriteError, @@ -25,7 +26,7 @@ import { import type { Topology } from '../sdam/topology'; import type { ClientSession } from '../sessions'; import { TimeoutContext } from '../timeout'; -import { abortable, supportsRetryableWrites } from '../utils'; +import { abortable, maxWireVersion, supportsRetryableWrites } from '../utils'; import { AggregateOperation } from './aggregate'; import { AbstractOperation, Aspect } from './operation'; @@ -81,7 +82,10 @@ export async function executeOperation< session = client.startSession({ owner, explicit: false }); } else if (session.hasEnded) { throw new MongoExpiredSessionError('Use of expired sessions is not permitted'); - } else if (session.snapshotEnabled && !topology.capabilities.supportsSnapshotReads) { + } else if ( + session.snapshotEnabled && + maxWireVersion(topology) < MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION + ) { throw new MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later'); } else if (session.client !== client) { throw new MongoInvalidArgumentError('ClientSession must be from the same MongoClient'); diff --git a/src/operations/find.ts b/src/operations/find.ts index c78c7c05e8c..6c9f8dafe3a 100644 --- a/src/operations/find.ts +++ b/src/operations/find.ts @@ -12,10 +12,8 @@ import { Aspect, defineAspects, type Hint } from './operation'; /** * @public - * @typeParam TSchema - Unused schema definition, deprecated usage, only specify `FindOptions` with no generic */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export interface FindOptions +export interface FindOptions extends Omit, AbstractCursorOptions { /** Sets the limit of documents returned in the query. */ @@ -76,14 +74,7 @@ export interface FindOptions } /** @public */ -export interface FindOneOptions extends FindOptions { - /** @deprecated Will be removed in the next major version. User provided value will be ignored. */ - batchSize?: number; - /** @deprecated Will be removed in the next major version. User provided value will be ignored. */ - limit?: number; - /** @deprecated Will be removed in the next major version. User provided value will be ignored. */ - noCursorTimeout?: boolean; -} +export type FindOneOptions = Omit; /** @internal */ export class FindOperation extends CommandOperation { diff --git a/src/read_preference.ts b/src/read_preference.ts index 209752dc865..0ca9c6758d0 100644 --- a/src/read_preference.ts +++ b/src/read_preference.ts @@ -63,10 +63,6 @@ export class ReadPreference { tags?: TagSet[]; hedge?: HedgeOptions; maxStalenessSeconds?: number; - /** - * @deprecated This will be removed as dead code in the next major version. - */ - minWireVersion?: number; public static PRIMARY = ReadPreferenceMode.primary; public static PRIMARY_PREFERRED = ReadPreferenceMode.primaryPreferred; @@ -100,7 +96,6 @@ export class ReadPreference { this.tags = tags; this.hedge = options?.hedge; this.maxStalenessSeconds = undefined; - this.minWireVersion = undefined; options = options ?? {}; if (options.maxStalenessSeconds != null) { @@ -109,10 +104,6 @@ export class ReadPreference { } this.maxStalenessSeconds = options.maxStalenessSeconds; - - // NOTE: The minimum required wire version is 5 for this read preference. If the existing - // topology has a lower value then a MongoError will be thrown during server selection. - this.minWireVersion = 5; } if (this.mode === ReadPreference.PRIMARY) { diff --git a/src/sdam/topology.ts b/src/sdam/topology.ts index 3d088caf6c3..5506e1bd015 100644 --- a/src/sdam/topology.ts +++ b/src/sdam/topology.ts @@ -393,10 +393,6 @@ export class Topology extends TypedEventEmitter { return this.s.options.serverApi; } - get capabilities(): ServerCapabilities { - return new ServerCapabilities(this.lastHello()); - } - /** Initiate server connect */ async connect(options?: ConnectOptions): Promise { this.connectionLock ??= this._connect(options); @@ -1103,52 +1099,3 @@ function isStaleServerDescription( compareTopologyVersion(currentTopologyVersion, incomingServerDescription.topologyVersion) > 0 ); } - -/** - * @public - * @deprecated This class will be removed as dead code in the next major version. - */ -export class ServerCapabilities { - maxWireVersion: number; - minWireVersion: number; - - constructor(hello: Document) { - this.minWireVersion = hello.minWireVersion || 0; - this.maxWireVersion = hello.maxWireVersion || 0; - } - - get hasAggregationCursor(): boolean { - return true; - } - - get hasWriteCommands(): boolean { - return true; - } - get hasTextSearch(): boolean { - return true; - } - - get hasAuthCommands(): boolean { - return true; - } - - get hasListCollectionsCommand(): boolean { - return true; - } - - get hasListIndexesCommand(): boolean { - return true; - } - - get supportsSnapshotReads(): boolean { - return this.maxWireVersion >= 13; - } - - get commandsTakeWriteConcern(): boolean { - return true; - } - - get commandsTakeCollation(): boolean { - return true; - } -} diff --git a/src/sessions.ts b/src/sessions.ts index 25031a41754..441ee030782 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -118,7 +118,7 @@ export class ClientSession /** @internal */ owner?: symbol | AbstractCursor; defaultTransactionOptions: TransactionOptions; - /** @deprecated - Will be made internal in the next major release */ + /** @internal */ transaction: Transaction; /** * @internal diff --git a/src/transactions.ts b/src/transactions.ts index 945d24dc31d..a9cfd9cf273 100644 --- a/src/transactions.ts +++ b/src/transactions.ts @@ -73,21 +73,15 @@ export interface TransactionOptions extends Omit) return filterOptions; } -interface HasRetryableWrites { - retryWrites?: boolean; -} -/** - * Applies retryWrites: true to a command if retryWrites is set on the command's database. - * @internal - * - * @param target - The target command to which we will apply retryWrites. - * @param db - The database from which we can inherit a retryWrites value. - */ -export function applyRetryableWrites(target: T, db?: Db): T { - if (db && db.s.options?.retryWrites) { - target.retryWrites = true; - } - - return target; -} - /** * Applies a write concern to a command based on well defined inheritance rules, optionally * detecting support for the write concern in the first place. diff --git a/test/integration/gridfs/gridfs.spec.test.ts b/test/integration/gridfs/gridfs.spec.test.ts index 7e73283cb68..60699615276 100644 --- a/test/integration/gridfs/gridfs.spec.test.ts +++ b/test/integration/gridfs/gridfs.spec.test.ts @@ -1,8 +1,18 @@ import { loadSpecTests } from '../../spec'; import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; +const SKIP = [ + 'delete when multiple revisions of the file exist', + 'delete when file name does not exist', + 'rename when multiple revisions of the file exist', + 'rename when file name does not exist' +]; + describe('GridFS Unified Tests', function () { runUnifiedSuite(loadSpecTests('gridfs'), ({ description }) => { + if (SKIP.includes(description)) { + return 'TODO(NODE-6511): Implement rename GridFS functionality'; + } return description === 'download when final chunk is missing' ? `TODO(NODE-xxxx)` : false; }); }); diff --git a/test/spec/gridfs/delete.json b/test/spec/gridfs/delete.json index 7a4ec27f887..9a9b22fc1ef 100644 --- a/test/spec/gridfs/delete.json +++ b/test/spec/gridfs/delete.json @@ -49,10 +49,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -64,10 +61,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0-with-empty-chunk", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -79,10 +73,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "c700ed4fdb1d27055aa3faa2c2432283", "filename": "length-2", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -94,10 +85,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "dd254cdc958e53abaa67da9f797125f5", "filename": "length-8", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} } ] @@ -197,10 +185,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0-with-empty-chunk", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -212,10 +197,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "c700ed4fdb1d27055aa3faa2c2432283", "filename": "length-2", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -227,10 +209,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "dd254cdc958e53abaa67da9f797125f5", "filename": "length-8", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} } ] @@ -330,10 +309,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -345,10 +321,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "c700ed4fdb1d27055aa3faa2c2432283", "filename": "length-2", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -360,10 +333,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "dd254cdc958e53abaa67da9f797125f5", "filename": "length-8", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} } ] @@ -448,10 +418,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -463,10 +430,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0-with-empty-chunk", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -478,10 +442,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "c700ed4fdb1d27055aa3faa2c2432283", "filename": "length-2", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} } ] @@ -536,7 +497,7 @@ } }, "expectError": { - "isError": true + "isClientError": true } } ], @@ -554,10 +515,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -569,10 +527,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0-with-empty-chunk", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -584,10 +539,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "c700ed4fdb1d27055aa3faa2c2432283", "filename": "length-2", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -599,10 +551,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "dd254cdc958e53abaa67da9f797125f5", "filename": "length-8", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} } ] @@ -701,7 +650,7 @@ } }, "expectError": { - "isError": true + "isClientError": true } } ], @@ -719,10 +668,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -734,10 +680,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0-with-empty-chunk", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -749,10 +692,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "c700ed4fdb1d27055aa3faa2c2432283", "filename": "length-2", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} } ] diff --git a/test/spec/gridfs/delete.yml b/test/spec/gridfs/delete.yml index b300cad1bc3..70593ac2799 100644 --- a/test/spec/gridfs/delete.yml +++ b/test/spec/gridfs/delete.yml @@ -30,40 +30,28 @@ initialData: length: 0 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "d41d8cd98f00b204e9800998ecf8427e" filename: "length-0" - contentType: "application/octet-stream" - aliases: [] metadata: {} - &file2 _id: { "$oid": "000000000000000000000002" } length: 0 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "d41d8cd98f00b204e9800998ecf8427e" filename: "length-0-with-empty-chunk" - contentType: "application/octet-stream" - aliases: [] metadata: {} - &file3 _id: { "$oid": "000000000000000000000003" } length: 2 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "c700ed4fdb1d27055aa3faa2c2432283" filename: "length-2" - contentType: "application/octet-stream" - aliases: [] metadata: {} - &file4 _id: { "$oid": "000000000000000000000004" } length: 8 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "dd254cdc958e53abaa67da9f797125f5" filename: "length-8" - contentType: "application/octet-stream" - aliases: [] metadata: {} - collectionName: *bucket0_chunks_collectionName databaseName: *database0Name @@ -153,7 +141,7 @@ tests: object: *bucket0 arguments: id: { $oid: "000000000000000000000000" } - expectError: { isError: true } # FileNotFound + expectError: { isClientError: true } # FileNotFound outcome: - collectionName: *bucket0_files_collectionName databaseName: *database0Name @@ -182,7 +170,7 @@ tests: object: *bucket0 arguments: id: { $oid: "000000000000000000000004" } - expectError: { isError: true } # FileNotFound + expectError: { isClientError: true } # FileNotFound outcome: - collectionName: *bucket0_files_collectionName databaseName: *database0Name diff --git a/test/spec/gridfs/deleteByName.json b/test/spec/gridfs/deleteByName.json new file mode 100644 index 00000000000..884d0300ce1 --- /dev/null +++ b/test/spec/gridfs/deleteByName.json @@ -0,0 +1,230 @@ +{ + "description": "gridfs-deleteByName", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "gridfs-tests" + } + }, + { + "bucket": { + "id": "bucket0", + "database": "database0" + } + }, + { + "collection": { + "id": "bucket0_files_collection", + "database": "database0", + "collectionName": "fs.files" + } + }, + { + "collection": { + "id": "bucket0_chunks_collection", + "database": "database0", + "collectionName": "fs.chunks" + } + } + ], + "initialData": [ + { + "collectionName": "fs.files", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "filename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000002" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "filename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000003" + }, + "length": 2, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "filename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000004" + }, + "length": 8, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "otherfilename", + "metadata": {} + } + ] + }, + { + "collectionName": "fs.chunks", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "files_id": { + "$oid": "000000000000000000000002" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + }, + { + "_id": { + "$oid": "000000000000000000000002" + }, + "files_id": { + "$oid": "000000000000000000000003" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + }, + { + "_id": { + "$oid": "000000000000000000000003" + }, + "files_id": { + "$oid": "000000000000000000000003" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + }, + { + "_id": { + "$oid": "000000000000000000000004" + }, + "files_id": { + "$oid": "000000000000000000000004" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + } + ] + } + ], + "tests": [ + { + "description": "delete when multiple revisions of the file exist", + "operations": [ + { + "name": "deleteByName", + "object": "bucket0", + "arguments": { + "filename": "filename" + } + } + ], + "outcome": [ + { + "collectionName": "fs.files", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000004" + }, + "length": 8, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "otherfilename", + "metadata": {} + } + ] + }, + { + "collectionName": "fs.chunks", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000004" + }, + "files_id": { + "$oid": "000000000000000000000004" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + } + ] + } + ] + }, + { + "description": "delete when file name does not exist", + "operations": [ + { + "name": "deleteByName", + "object": "bucket0", + "arguments": { + "filename": "missing-file" + }, + "expectError": { + "isClientError": true + } + } + ] + } + ] +} diff --git a/test/spec/gridfs/deleteByName.yml b/test/spec/gridfs/deleteByName.yml new file mode 100644 index 00000000000..b63b15633ae --- /dev/null +++ b/test/spec/gridfs/deleteByName.yml @@ -0,0 +1,102 @@ +description: "gridfs-deleteByName" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name gridfs-tests + - bucket: + id: &bucket0 bucket0 + database: *database0 + - collection: + id: &bucket0_files_collection bucket0_files_collection + database: *database0 + collectionName: &bucket0_files_collectionName fs.files + - collection: + id: &bucket0_chunks_collection bucket0_chunks_collection + database: *database0 + collectionName: &bucket0_chunks_collectionName fs.chunks + +initialData: + - collectionName: *bucket0_files_collectionName + databaseName: *database0Name + documents: + - &file1 + _id: { "$oid": "000000000000000000000001" } + length: 0 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "filename" + metadata: {} + - &file2 + _id: { "$oid": "000000000000000000000002" } + length: 0 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "filename" + metadata: {} + - &file3 + _id: { "$oid": "000000000000000000000003" } + length: 2 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "filename" + metadata: {} + - &file4 + _id: { "$oid": "000000000000000000000004" } + length: 8 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "otherfilename" + metadata: {} + - collectionName: *bucket0_chunks_collectionName + databaseName: *database0Name + documents: + - &file2_chunk0 + _id: { "$oid": "000000000000000000000001" } + files_id: { "$oid": "000000000000000000000002" } + n: 0 + data: { "$binary": { "base64": "", "subType": "00" } } + - &file3_chunk0 + _id: { "$oid": "000000000000000000000002" } + files_id: { "$oid": "000000000000000000000003" } + n: 0 + data: { "$binary": { "base64": "", "subType": "00" } } + - &file3_chunk1 + _id: { "$oid": "000000000000000000000003" } + files_id: { "$oid": "000000000000000000000003" } + n: 0 + data: { "$binary": { "base64": "", "subType": "00" } } + - &file4_chunk0 + _id: { "$oid": "000000000000000000000004" } + files_id: { "$oid": "000000000000000000000004" } + n: 0 + data: { "$binary": { "base64": "", "subType": "00" } } + +tests: + - description: "delete when multiple revisions of the file exist" + operations: + - name: deleteByName + object: *bucket0 + arguments: + filename: filename + outcome: + - collectionName: *bucket0_files_collectionName + databaseName: *database0Name + documents: + - <<: *file4 + - collectionName: *bucket0_chunks_collectionName + databaseName: *database0Name + documents: + - *file4_chunk0 + - description: "delete when file name does not exist" + operations: + - name: deleteByName + object: *bucket0 + arguments: + filename: missing-file + expectError: { isClientError: true } # FileNotFound diff --git a/test/spec/gridfs/download.json b/test/spec/gridfs/download.json index 48d32462181..67658ac5124 100644 --- a/test/spec/gridfs/download.json +++ b/test/spec/gridfs/download.json @@ -49,10 +49,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -64,10 +61,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "d41d8cd98f00b204e9800998ecf8427e", "filename": "length-0-with-empty-chunk", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -79,10 +73,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "c700ed4fdb1d27055aa3faa2c2432283", "filename": "length-2", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -94,10 +85,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "dd254cdc958e53abaa67da9f797125f5", "filename": "length-8", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -109,10 +97,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "57d83cd477bfb1ccd975ab33d827a92b", "filename": "length-10", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -124,9 +109,6 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "c700ed4fdb1d27055aa3faa2c2432283", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} } ] @@ -356,7 +338,7 @@ } }, "expectError": { - "isError": true + "isClientError": true } } ] @@ -388,7 +370,7 @@ } }, "expectError": { - "isError": true + "isClientError": true } } ] @@ -420,7 +402,7 @@ } }, "expectError": { - "isError": true + "isClientError": true } } ] @@ -489,7 +471,7 @@ } }, "expectError": { - "isError": true + "isClientError": true } } ] @@ -532,7 +514,7 @@ } }, "expectError": { - "isError": true + "isClientError": true } } ] diff --git a/test/spec/gridfs/download.yml b/test/spec/gridfs/download.yml index 3da5ee950f1..b9b36a5f48a 100644 --- a/test/spec/gridfs/download.yml +++ b/test/spec/gridfs/download.yml @@ -29,55 +29,37 @@ initialData: length: 0 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "d41d8cd98f00b204e9800998ecf8427e" filename: "length-0" - contentType: "application/octet-stream" - aliases: [] metadata: {} - _id: { "$oid": "000000000000000000000002" } length: 0 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "d41d8cd98f00b204e9800998ecf8427e" filename: "length-0-with-empty-chunk" - contentType: "application/octet-stream" - aliases: [] metadata: {} - _id: { "$oid": "000000000000000000000003" } length: 2 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "c700ed4fdb1d27055aa3faa2c2432283" filename: "length-2" - contentType: "application/octet-stream" - aliases: [] metadata: {} - _id: { "$oid": "000000000000000000000004" } length: 8 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "dd254cdc958e53abaa67da9f797125f5" filename: "length-8" - contentType: "application/octet-stream" - aliases: [] metadata: {} - _id: { "$oid": "000000000000000000000005" } length: 10 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "57d83cd477bfb1ccd975ab33d827a92b" filename: "length-10" - contentType: "application/octet-stream" - aliases: [] metadata: {} - _id: { "$oid": "000000000000000000000006" } length: 2 chunkSize: 4 uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } - md5: "c700ed4fdb1d27055aa3faa2c2432283" # filename is intentionally omitted - contentType: "application/octet-stream" - aliases: [] metadata: {} - collectionName: *bucket0_chunks_collectionName databaseName: *database0Name @@ -157,7 +139,7 @@ tests: object: *bucket0 arguments: id: { $oid: "000000000000000000000000" } - expectError: { isError: true } # FileNotFound + expectError: { isClientError: true } # FileNotFound - description: "download when an intermediate chunk is missing" operations: - name: deleteOne @@ -172,7 +154,7 @@ tests: object: *bucket0 arguments: id: { $oid: "000000000000000000000005" } - expectError: { isError: true } # ChunkIsMissing + expectError: { isClientError: true } # ChunkIsMissing - description: "download when final chunk is missing" operations: - name: deleteOne @@ -187,7 +169,7 @@ tests: object: *bucket0 arguments: id: { $oid: "000000000000000000000005" } - expectError: { isError: true } # ChunkIsMissing + expectError: { isClientError: true } # ChunkIsMissing - description: "download when an intermediate chunk is the wrong size" operations: - name: bulkWrite @@ -213,7 +195,7 @@ tests: object: *bucket0 arguments: id: { $oid: "000000000000000000000005" } - expectError: { isError: true } # ChunkIsWrongSize + expectError: { isClientError: true } # ChunkIsWrongSize - description: "download when final chunk is the wrong size" operations: - name: updateOne @@ -231,7 +213,7 @@ tests: object: *bucket0 arguments: id: { $oid: "000000000000000000000005" } - expectError: { isError: true } # ChunkIsWrongSize + expectError: { isClientError: true } # ChunkIsWrongSize - description: "download legacy file with no name" operations: - name: download diff --git a/test/spec/gridfs/downloadByName.json b/test/spec/gridfs/downloadByName.json index cd446639572..45abaf7b42e 100644 --- a/test/spec/gridfs/downloadByName.json +++ b/test/spec/gridfs/downloadByName.json @@ -49,10 +49,7 @@ "uploadDate": { "$date": "1970-01-01T00:00:00.000Z" }, - "md5": "47ed733b8d10be225eceba344d533586", "filename": "abc", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -64,10 +61,7 @@ "uploadDate": { "$date": "1970-01-02T00:00:00.000Z" }, - "md5": "b15835f133ff2e27c7cb28117bfae8f4", "filename": "abc", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -79,10 +73,7 @@ "uploadDate": { "$date": "1970-01-03T00:00:00.000Z" }, - "md5": "eccbc87e4b5ce2fe28308fd9f2a7baf3", "filename": "abc", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -94,10 +85,7 @@ "uploadDate": { "$date": "1970-01-04T00:00:00.000Z" }, - "md5": "f623e75af30e62bbd73d6df5b50bb7b5", "filename": "abc", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} }, { @@ -109,10 +97,7 @@ "uploadDate": { "$date": "1970-01-05T00:00:00.000Z" }, - "md5": "4c614360da93c0a041b22e537de151eb", "filename": "abc", - "contentType": "application/octet-stream", - "aliases": [], "metadata": {} } ] @@ -305,7 +290,7 @@ "filename": "xyz" }, "expectError": { - "isError": true + "isClientError": true } } ] @@ -321,7 +306,7 @@ "revision": 999 }, "expectError": { - "isError": true + "isClientError": true } } ] diff --git a/test/spec/gridfs/downloadByName.yml b/test/spec/gridfs/downloadByName.yml index 6dfc602b665..26d1301a61b 100644 --- a/test/spec/gridfs/downloadByName.yml +++ b/test/spec/gridfs/downloadByName.yml @@ -29,46 +29,31 @@ initialData: length: 1 chunkSize: 4 uploadDate: { $date: "1970-01-01T00:00:00.000Z" } - md5: "47ed733b8d10be225eceba344d533586" filename: "abc" - contentType: "application/octet-stream" - aliases: [] metadata: {} - _id: { $oid: "000000000000000000000002" } length: 1 chunkSize: 4 uploadDate: { $date: "1970-01-02T00:00:00.000Z" } - md5: "b15835f133ff2e27c7cb28117bfae8f4" filename: "abc" - contentType: "application/octet-stream" - aliases: [] metadata: {} - _id: { $oid: "000000000000000000000003" } length: 1 chunkSize: 4 uploadDate: { $date: "1970-01-03T00:00:00.000Z" } - md5: "eccbc87e4b5ce2fe28308fd9f2a7baf3" filename: "abc" - contentType: "application/octet-stream" - aliases: [] metadata: {} - _id: { $oid: "000000000000000000000004" } length: 1 chunkSize: 4 uploadDate: { $date: "1970-01-04T00:00:00.000Z" } - md5: "f623e75af30e62bbd73d6df5b50bb7b5" filename: "abc" - contentType: "application/octet-stream" - aliases: [] metadata: {} - _id: { $oid: "000000000000000000000005" } length: 1 chunkSize: 4 uploadDate: { $date: "1970-01-05T00:00:00.000Z" } - md5: "4c614360da93c0a041b22e537de151eb" filename: "abc" - contentType: "application/octet-stream" - aliases: [] metadata: {} - collectionName: *bucket0_chunks_collectionName databaseName: *database0Name @@ -148,7 +133,7 @@ tests: object: *bucket0 arguments: filename: "xyz" - expectError: { isError: true } # FileNotFound + expectError: { isClientError: true } # FileNotFound - description: "downloadByName when revision does not exist" operations: - name: downloadByName @@ -156,4 +141,4 @@ tests: arguments: filename: "abc" revision: 999 - expectError: { isError: true } # RevisionNotFound + expectError: { isClientError: true } # RevisionNotFound diff --git a/test/spec/gridfs/rename.json b/test/spec/gridfs/rename.json new file mode 100644 index 00000000000..08064d4a5ce --- /dev/null +++ b/test/spec/gridfs/rename.json @@ -0,0 +1,179 @@ +{ + "description": "gridfs-rename", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "gridfs-tests" + } + }, + { + "bucket": { + "id": "bucket0", + "database": "database0" + } + }, + { + "collection": { + "id": "bucket0_files_collection", + "database": "database0", + "collectionName": "fs.files" + } + }, + { + "collection": { + "id": "bucket0_chunks_collection", + "database": "database0", + "collectionName": "fs.chunks" + } + } + ], + "initialData": [ + { + "collectionName": "fs.files", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "filename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000002" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "filename", + "metadata": {} + } + ] + }, + { + "collectionName": "fs.chunks", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "files_id": { + "$oid": "000000000000000000000002" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + } + ] + } + ], + "tests": [ + { + "description": "rename by id", + "operations": [ + { + "name": "rename", + "object": "bucket0", + "arguments": { + "id": { + "$oid": "000000000000000000000001" + }, + "newFilename": "newfilename" + } + } + ], + "outcome": [ + { + "collectionName": "fs.files", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "newfilename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000002" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "filename", + "metadata": {} + } + ] + }, + { + "collectionName": "fs.chunks", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "files_id": { + "$oid": "000000000000000000000002" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + } + ] + } + ] + }, + { + "description": "rename when file id does not exist", + "operations": [ + { + "name": "rename", + "object": "bucket0", + "arguments": { + "id": { + "$oid": "000000000000000000000003" + }, + "newFilename": "newfilename" + }, + "expectError": { + "isClientError": true + } + } + ] + } + ] +} diff --git a/test/spec/gridfs/rename.yml b/test/spec/gridfs/rename.yml new file mode 100644 index 00000000000..22035329985 --- /dev/null +++ b/test/spec/gridfs/rename.yml @@ -0,0 +1,78 @@ +description: "gridfs-rename" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name gridfs-tests + - bucket: + id: &bucket0 bucket0 + database: *database0 + - collection: + id: &bucket0_files_collection bucket0_files_collection + database: *database0 + collectionName: &bucket0_files_collectionName fs.files + - collection: + id: &bucket0_chunks_collection bucket0_chunks_collection + database: *database0 + collectionName: &bucket0_chunks_collectionName fs.chunks + +initialData: + - collectionName: *bucket0_files_collectionName + databaseName: *database0Name + documents: + - &file1 + _id: { "$oid": "000000000000000000000001" } + length: 0 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "filename" + metadata: {} + - &file2 + _id: { "$oid": "000000000000000000000002" } + length: 0 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "filename" + metadata: {} + - collectionName: *bucket0_chunks_collectionName + databaseName: *database0Name + documents: + - &file2_chunk0 + _id: { "$oid": "000000000000000000000001" } + files_id: { "$oid": "000000000000000000000002" } + n: 0 + data: { "$binary": { "base64": "", "subType": "00" } } + +tests: + - description: "rename by id" + operations: + - name: rename + object: *bucket0 + arguments: + id: { "$oid": "000000000000000000000001" } + newFilename: newfilename + outcome: + - collectionName: *bucket0_files_collectionName + databaseName: *database0Name + documents: + - <<: *file1 + filename: newfilename + - <<: *file2 + filename: filename + - collectionName: *bucket0_chunks_collectionName + databaseName: *database0Name + documents: + - *file2_chunk0 + - description: "rename when file id does not exist" + operations: + - name: rename + object: *bucket0 + arguments: + id: { "$oid": "000000000000000000000003" } + newFilename: newfilename + expectError: { isClientError: true } # FileNotFound diff --git a/test/spec/gridfs/renameByName.json b/test/spec/gridfs/renameByName.json new file mode 100644 index 00000000000..26f04fb9e0f --- /dev/null +++ b/test/spec/gridfs/renameByName.json @@ -0,0 +1,313 @@ +{ + "description": "gridfs-renameByName", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "gridfs-tests" + } + }, + { + "bucket": { + "id": "bucket0", + "database": "database0" + } + }, + { + "collection": { + "id": "bucket0_files_collection", + "database": "database0", + "collectionName": "fs.files" + } + }, + { + "collection": { + "id": "bucket0_chunks_collection", + "database": "database0", + "collectionName": "fs.chunks" + } + } + ], + "initialData": [ + { + "collectionName": "fs.files", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "filename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000002" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "filename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000003" + }, + "length": 2, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "filename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000004" + }, + "length": 8, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "otherfilename", + "metadata": {} + } + ] + }, + { + "collectionName": "fs.chunks", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "files_id": { + "$oid": "000000000000000000000002" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + }, + { + "_id": { + "$oid": "000000000000000000000002" + }, + "files_id": { + "$oid": "000000000000000000000003" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + }, + { + "_id": { + "$oid": "000000000000000000000003" + }, + "files_id": { + "$oid": "000000000000000000000004" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + }, + { + "_id": { + "$oid": "000000000000000000000004" + }, + "files_id": { + "$oid": "000000000000000000000004" + }, + "n": 1, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + } + ] + } + ], + "tests": [ + { + "description": "rename when multiple revisions of the file exist", + "operations": [ + { + "name": "renameByName", + "object": "bucket0", + "arguments": { + "filename": "filename", + "newFilename": "newfilename" + } + } + ], + "outcome": [ + { + "collectionName": "fs.files", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "newfilename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000002" + }, + "length": 0, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "newfilename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000003" + }, + "length": 2, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "newfilename", + "metadata": {} + }, + { + "_id": { + "$oid": "000000000000000000000004" + }, + "length": 8, + "chunkSize": 4, + "uploadDate": { + "$date": "1970-01-01T00:00:00.000Z" + }, + "filename": "otherfilename", + "metadata": {} + } + ] + }, + { + "collectionName": "fs.chunks", + "databaseName": "gridfs-tests", + "documents": [ + { + "_id": { + "$oid": "000000000000000000000001" + }, + "files_id": { + "$oid": "000000000000000000000002" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + }, + { + "_id": { + "$oid": "000000000000000000000002" + }, + "files_id": { + "$oid": "000000000000000000000003" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + }, + { + "_id": { + "$oid": "000000000000000000000003" + }, + "files_id": { + "$oid": "000000000000000000000004" + }, + "n": 0, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + }, + { + "_id": { + "$oid": "000000000000000000000004" + }, + "files_id": { + "$oid": "000000000000000000000004" + }, + "n": 1, + "data": { + "$binary": { + "base64": "", + "subType": "00" + } + } + } + ] + } + ] + }, + { + "description": "rename when file name does not exist", + "operations": [ + { + "name": "renameByName", + "object": "bucket0", + "arguments": { + "filename": "missing-file", + "newFilename": "newfilename" + }, + "expectError": { + "isClientError": true + } + } + ] + } + ] +} diff --git a/test/spec/gridfs/renameByName.yml b/test/spec/gridfs/renameByName.yml new file mode 100644 index 00000000000..f628ca9c5fb --- /dev/null +++ b/test/spec/gridfs/renameByName.yml @@ -0,0 +1,113 @@ +description: "gridfs-renameByName" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name gridfs-tests + - bucket: + id: &bucket0 bucket0 + database: *database0 + - collection: + id: &bucket0_files_collection bucket0_files_collection + database: *database0 + collectionName: &bucket0_files_collectionName fs.files + - collection: + id: &bucket0_chunks_collection bucket0_chunks_collection + database: *database0 + collectionName: &bucket0_chunks_collectionName fs.chunks + +initialData: + - collectionName: *bucket0_files_collectionName + databaseName: *database0Name + documents: + - &file1 + _id: { "$oid": "000000000000000000000001" } + length: 0 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "filename" + metadata: {} + - &file2 + _id: { "$oid": "000000000000000000000002" } + length: 0 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "filename" + metadata: {} + - &file3 + _id: { "$oid": "000000000000000000000003" } + length: 2 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "filename" + metadata: {} + - &file4 + _id: { "$oid": "000000000000000000000004" } + length: 8 + chunkSize: 4 + uploadDate: { "$date": "1970-01-01T00:00:00.000Z" } + filename: "otherfilename" + metadata: {} + - collectionName: *bucket0_chunks_collectionName + databaseName: *database0Name + documents: + - &file2_chunk0 + _id: { "$oid": "000000000000000000000001" } + files_id: { "$oid": "000000000000000000000002" } + n: 0 + data: { "$binary": { "base64": "", "subType": "00" } } + - &file3_chunk0 + _id: { "$oid": "000000000000000000000002" } + files_id: { "$oid": "000000000000000000000003" } + n: 0 + data: { "$binary": { "base64": "", "subType": "00" } } + - &file4_chunk0 + _id: { "$oid": "000000000000000000000003" } + files_id: { "$oid": "000000000000000000000004" } + n: 0 + data: { "$binary": { "base64": "", "subType": "00" } } + - &file4_chunk1 + _id: { "$oid": "000000000000000000000004" } + files_id: { "$oid": "000000000000000000000004" } + n: 1 + data: { "$binary": { "base64": "", "subType": "00" } } + +tests: + - description: "rename when multiple revisions of the file exist" + operations: + - name: renameByName + object: *bucket0 + arguments: + filename: filename + newFilename: newfilename + outcome: + - collectionName: *bucket0_files_collectionName + databaseName: *database0Name + documents: + - <<: *file1 + filename: newfilename + - <<: *file2 + filename: newfilename + - <<: *file3 + filename: newfilename + - <<: *file4 + - collectionName: *bucket0_chunks_collectionName + databaseName: *database0Name + documents: + - *file2_chunk0 + - *file3_chunk0 + - *file4_chunk0 + - *file4_chunk1 + - description: "rename when file name does not exist" + operations: + - name: renameByName + object: *bucket0 + arguments: + filename: missing-file + newFilename: newfilename + expectError: { isClientError: true } # FileNotFound diff --git a/test/spec/gridfs/upload.json b/test/spec/gridfs/upload.json index 97e18d2bc25..3c1644653a5 100644 --- a/test/spec/gridfs/upload.json +++ b/test/spec/gridfs/upload.json @@ -470,75 +470,6 @@ } ] }, - { - "description": "upload when contentType is provided", - "operations": [ - { - "name": "upload", - "object": "bucket0", - "arguments": { - "filename": "filename", - "source": { - "$$hexBytes": "11" - }, - "chunkSizeBytes": 4, - "contentType": "image/jpeg" - }, - "expectResult": { - "$$type": "objectId" - }, - "saveResultAsEntity": "uploadedObjectId" - }, - { - "name": "find", - "object": "bucket0_files_collection", - "arguments": { - "filter": {} - }, - "expectResult": [ - { - "_id": { - "$$matchesEntity": "uploadedObjectId" - }, - "length": 1, - "chunkSize": 4, - "uploadDate": { - "$$type": "date" - }, - "md5": { - "$$unsetOrMatches": "47ed733b8d10be225eceba344d533586" - }, - "filename": "filename", - "contentType": "image/jpeg" - } - ] - }, - { - "name": "find", - "object": "bucket0_chunks_collection", - "arguments": { - "filter": {} - }, - "expectResult": [ - { - "_id": { - "$$type": "objectId" - }, - "files_id": { - "$$matchesEntity": "uploadedObjectId" - }, - "n": 0, - "data": { - "$binary": { - "base64": "EQ==", - "subType": "00" - } - } - } - ] - } - ] - }, { "description": "upload when metadata is provided", "operations": [ diff --git a/test/spec/gridfs/upload.yml b/test/spec/gridfs/upload.yml index 27f3186fc48..96fc5e98639 100644 --- a/test/spec/gridfs/upload.yml +++ b/test/spec/gridfs/upload.yml @@ -222,38 +222,6 @@ tests: files_id: { $$matchesEntity: *uploadedObjectId } n: 1 data: { $binary: { base64: "VWZ3iA==", subType: "00" } } # hex 55667788 - - description: "upload when contentType is provided" - operations: - - name: upload - object: *bucket0 - arguments: - filename: "filename" - source: { $$hexBytes: "11" } - chunkSizeBytes: 4 - contentType: "image/jpeg" - expectResult: { $$type: objectId } - saveResultAsEntity: *uploadedObjectId - - name: find - object: *bucket0_files_collection - arguments: - filter: {} - expectResult: - - _id: { $$matchesEntity: *uploadedObjectId } - length: 1 - chunkSize: 4 - uploadDate: { $$type: date } - md5: { $$unsetOrMatches: "47ed733b8d10be225eceba344d533586" } - filename: filename - contentType: "image/jpeg" - - name: find - object: *bucket0_chunks_collection - arguments: - filter: {} - expectResult: - - _id: { $$type: objectId } - files_id: { $$matchesEntity: *uploadedObjectId } - n: 0 - data: { $binary: { base64: "EQ==", subType: "00" } } # hex 11 - description: "upload when metadata is provided" operations: - name: upload diff --git a/test/types/community/collection/findX.test-d.ts b/test/types/community/collection/findX.test-d.ts index 0de99ee7d49..f0624e3d5a6 100644 --- a/test/types/community/collection/findX.test-d.ts +++ b/test/types/community/collection/findX.test-d.ts @@ -208,10 +208,6 @@ expectType>>( colorCollection.find<{ color: string }>({ color: { $in: colorsFreeze } }); colorCollection.find<{ color: string }>({ color: { $in: ['regularArray'] } }); -// This is a regression test that we don't remove the unused generic in FindOptions -const findOptions: FindOptions<{ a: number }> = {}; -expectType(findOptions); - // Ensure users can create a custom Db type that only contains specific // collections (which are, in turn, strongly typed): type Person = { diff --git a/test/unit/connection_string.test.ts b/test/unit/connection_string.test.ts index 62adaab40bb..e53eb7e51f2 100644 --- a/test/unit/connection_string.test.ts +++ b/test/unit/connection_string.test.ts @@ -1,4 +1,3 @@ -import { once } from 'node:events'; import * as process from 'node:process'; import { expect } from 'chai'; @@ -794,42 +793,6 @@ describe('Connection String', function () { expect(() => new MongoClient('mango+srv://localhost:23')).to.throw(/Invalid scheme/i); }); - describe('when deprecated options are used', () => { - it('useNewUrlParser emits a warning', async () => { - let willBeWarning = once(process, 'warning'); - parseOptions('mongodb://host?useNewUrlParser=true'); - let [warning] = await willBeWarning; - expect(warning) - .to.have.property('message') - .that.matches(/useNewUrlParser has no effect/); - - willBeWarning = once(process, 'warning'); - //@ts-expect-error: using unsupported option on purpose - parseOptions('mongodb://host', { useNewUrlParser: true }); - [warning] = await willBeWarning; - expect(warning) - .to.have.property('message') - .that.matches(/useNewUrlParser has no effect/); - }); - - it('useUnifiedTopology emits a warning', async () => { - let willBeWarning = once(process, 'warning'); - parseOptions('mongodb://host?useUnifiedTopology=true'); - let [warning] = await willBeWarning; - expect(warning) - .to.have.property('message') - .that.matches(/useUnifiedTopology has no effect/); - - willBeWarning = once(process, 'warning'); - //@ts-expect-error: using unsupported option on purpose - parseOptions('mongodb://host', { useUnifiedTopology: true }); - [warning] = await willBeWarning; - expect(warning) - .to.have.property('message') - .that.matches(/useUnifiedTopology has no effect/); - }); - }); - describe('when mongodbLogPath is in options', function () { let stderrStub; let stdoutStub; diff --git a/test/unit/mongo_client.test.ts b/test/unit/mongo_client.test.ts index 065cc306ba0..f0d2cd110eb 100644 --- a/test/unit/mongo_client.test.ts +++ b/test/unit/mongo_client.test.ts @@ -273,8 +273,6 @@ describe('MongoClient', function () { expect(options.readPreference.mode).to.equal('nearest'); expect(options.readPreference.tags).to.be.an('array').that.includes(tag); expect(options.readPreference.maxStalenessSeconds).to.equal(20); - // maxStalenessSeconds sets the minWireVersion - expect(options.readPreference.minWireVersion).to.be.at.least(5); }); it('should throw when given a readpreference options with an unsupported type', () => {