From 4f348d9d6e90023b45d06045d2cb7cc90f9239e4 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Fri, 12 May 2023 14:00:35 -0600 Subject: [PATCH 01/24] add search index helpers --- src/collection.ts | 83 +++++++++++++++++++++---- src/db.ts | 5 ++ src/operations/search_indexes/create.ts | 44 +++++++++++++ src/operations/search_indexes/drop.ts | 39 ++++++++++++ src/operations/search_indexes/list.ts | 19 ++++++ src/operations/search_indexes/update.ts | 36 +++++++++++ src/utils.ts | 15 ++++- 7 files changed, 227 insertions(+), 14 deletions(-) create mode 100644 src/operations/search_indexes/create.ts create mode 100644 src/operations/search_indexes/drop.ts create mode 100644 src/operations/search_indexes/list.ts create mode 100644 src/operations/search_indexes/update.ts diff --git a/src/collection.ts b/src/collection.ts index 95b7447bf9e..744b83af6b6 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -8,7 +8,7 @@ import { FindCursor } from './cursor/find_cursor'; import { ListIndexesCursor } from './cursor/list_indexes_cursor'; import type { Db } from './db'; import { MongoInvalidArgumentError } from './error'; -import type { PkFactory } from './mongo_client'; +import type { MongoClient, PkFactory } from './mongo_client'; import type { Filter, Flatten, @@ -70,6 +70,16 @@ import { IsCappedOperation } from './operations/is_capped'; import type { Hint, OperationOptions } from './operations/operation'; import { OptionsOperation } from './operations/options_operation'; import { RenameOperation, RenameOptions } from './operations/rename'; +import { + CreateSearchIndexesOperation, + SearchIndexDescription +} from './operations/search_indexes/create'; +import { DropSearchIndexOperation } from './operations/search_indexes/drop'; +import { + ListSearchIndexesCursor, + ListSearchIndexesOptions +} from './operations/search_indexes/list'; +import { UpdateSearchIndexOperation } from './operations/search_indexes/update'; import { CollStats, CollStatsOperation, CollStatsOptions } from './operations/stats'; import { ReplaceOneOperation, @@ -84,7 +94,7 @@ import { ReadPreference, ReadPreferenceLike } from './read_preference'; import { checkCollectionName, DEFAULT_PK_FACTORY, - MongoDBNamespace, + MongoDBCollectionNamespace, normalizeHintField, resolveOptions } from './utils'; @@ -115,7 +125,7 @@ export interface CollectionPrivate { pkFactory: PkFactory; db: Db; options: any; - namespace: MongoDBNamespace; + namespace: MongoDBCollectionNamespace; readPreference?: ReadPreference; bsonOptions: BSONSerializeOptions; collectionHint?: Hint; @@ -164,7 +174,7 @@ export class Collection { this.s = { db, options, - namespace: new MongoDBNamespace(db.databaseName, name), + namespace: new MongoDBCollectionNamespace(db.databaseName, name), pkFactory: db.options?.pkFactory ?? DEFAULT_PK_FACTORY, readPreference: ReadPreference.fromOptions(options), bsonOptions: resolveBSONOptions(options, db), @@ -173,6 +183,11 @@ export class Collection { }; } + /** @internal */ + get client(): MongoClient { + return this.s.db.client; + } + /** * The name of the database this collection belongs to */ @@ -184,15 +199,19 @@ export class Collection { * The name of this collection */ get collectionName(): string { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return this.s.namespace.collection!; + return this.s.namespace.collection; } /** * The namespace of this collection, in the format `${this.dbName}.${this.collectionName}` */ get namespace(): string { - return this.s.namespace.toString(); + return this.mongoDBNamespace.toString(); + } + + /** @internal */ + get mongoDBNamespace(): MongoDBCollectionNamespace { + return this.s.namespace; } /** @@ -976,11 +995,51 @@ export class Collection { async count(filter: Filter = {}, options: CountOptions = {}): Promise { return executeOperation( this.s.db.s.client, - new CountOperation( - MongoDBNamespace.fromString(this.namespace), - filter, - resolveOptions(this, options) - ) + new CountOperation(this.mongoDBNamespace, filter, resolveOptions(this, options)) + ); + } + + listSearchIndexes(options?: ListSearchIndexesOptions): ListSearchIndexesCursor; + listSearchIndexes(indexName: string, options?: ListSearchIndexesOptions): ListSearchIndexesCursor; + listSearchIndexes( + indexName?: string | ListSearchIndexesOptions, + options?: ListSearchIndexesOptions + ): ListSearchIndexesCursor { + // todo: options handling + + return ListSearchIndexesCursor.create(this, indexName as any, options); + } + + async createSearchIndex( + description: SearchIndexDescription, + options: Document = {} + ): Promise { + const indexes = await this.createSearchIndexes([description], options); + return indexes[0]; + } + + async createSearchIndexes( + descriptions: ReadonlyArray, + options: Document = {} + ): Promise { + return executeOperation( + this.s.db.s.client, + new CreateSearchIndexesOperation(this, descriptions, options) + ); + } + + async dropSearchIndex(name: string, options: Document = {}): Promise { + return executeOperation(this.s.db.s.client, new DropSearchIndexOperation(this, name, options)); + } + + async updateSearchIndex( + name: string, + definition: Document, + options: Document = {} + ): Promise { + return executeOperation( + this.s.db.s.client, + new UpdateSearchIndexOperation(this, name, definition, options) ); } } diff --git a/src/db.ts b/src/db.ts index 548d1830943..e70057c45e9 100644 --- a/src/db.ts +++ b/src/db.ts @@ -165,6 +165,11 @@ export class Db { }; } + /** @internal */ + get client(): MongoClient { + return this.s.client; + } + get databaseName(): string { return this.s.namespace.db; } diff --git a/src/operations/search_indexes/create.ts b/src/operations/search_indexes/create.ts new file mode 100644 index 00000000000..5960231d119 --- /dev/null +++ b/src/operations/search_indexes/create.ts @@ -0,0 +1,44 @@ +import type { Document } from 'bson'; + +import type { Collection } from '../../collection'; +import type { Server } from '../../sdam/server'; +import type { ClientSession } from '../../sessions'; +import type { Callback } from '../../utils'; +import { AbstractOperation } from '../operation'; + +export interface SearchIndexDescription { + name?: string; + description: Document; +} + +export class CreateSearchIndexesOperation extends AbstractOperation { + constructor( + private collection: Collection, + private descriptions: ReadonlyArray, + override options: Document = {} + ) { + super(options); + } + + execute(server: Server, session: ClientSession | undefined, callback: Callback): void { + const namespace = this.collection.mongoDBNamespace; + const command = { + createSearchIndexes: namespace.collection, + indexes: this.descriptions + }; + + server.command(namespace, command, { session }, (err, res) => { + if (err || !res) { + callback(err); + return; + } + + const indexesCreated: Array<{ name: string }> = res?.indexesCreated ?? []; + + callback( + undefined, + indexesCreated.map(({ name }) => name) + ); + }); + } +} diff --git a/src/operations/search_indexes/drop.ts b/src/operations/search_indexes/drop.ts new file mode 100644 index 00000000000..87aeb764355 --- /dev/null +++ b/src/operations/search_indexes/drop.ts @@ -0,0 +1,39 @@ +import type { Document } from 'bson'; + +import type { Collection } from '../../collection'; +import type { Server } from '../../sdam/server'; +import type { ClientSession } from '../../sessions'; +import type { Callback } from '../../utils'; +import { AbstractOperation } from '../operation'; + +export class DropSearchIndexOperation extends AbstractOperation { + /** @internal */ + constructor( + private collection: Collection, + private name: string, + override options: Document = {} + ) { + super(options); + } + + execute(server: Server, session: ClientSession | undefined, callback: Callback): void { + const namespace = this.collection.mongoDBNamespace; + + const command: Document = { + dropSearchIndex: namespace.collection + }; + + if (typeof this.name === 'string') { + command.name = this.name; + } + + server.command(namespace, command, { session }, err => { + if (err) { + callback(err); + return; + } + + callback(); + }); + } +} diff --git a/src/operations/search_indexes/list.ts b/src/operations/search_indexes/list.ts new file mode 100644 index 00000000000..35fb0cac99a --- /dev/null +++ b/src/operations/search_indexes/list.ts @@ -0,0 +1,19 @@ +import type { Collection } from '../../collection'; +import { AggregationCursor } from '../../cursor/aggregation_cursor'; +import type { AggregateOptions } from '../aggregate'; + +export type ListSearchIndexesOptions = AggregateOptions; + +export class ListSearchIndexesCursor extends AggregationCursor<{ name: string }> { + /** @internal */ + static create( + collection: Collection, + name: string | null, + options: ListSearchIndexesOptions = {} + ): ListSearchIndexesCursor { + const client = collection.client; + const ns = collection.mongoDBNamespace; + const pipeline = name == null ? [{ $listIndexes: {} }] : [{ $listSearchIndexes: { name } }]; + return new ListSearchIndexesCursor(client, ns, pipeline, options); + } +} diff --git a/src/operations/search_indexes/update.ts b/src/operations/search_indexes/update.ts new file mode 100644 index 00000000000..08586c6dde0 --- /dev/null +++ b/src/operations/search_indexes/update.ts @@ -0,0 +1,36 @@ +import type { Document } from 'bson'; + +import type { Collection } from '../../collection'; +import type { Server } from '../../sdam/server'; +import type { ClientSession } from '../../sessions'; +import type { Callback } from '../../utils'; +import { AbstractOperation } from '../operation'; + +export class UpdateSearchIndexOperation extends AbstractOperation { + constructor( + private collection: Collection, + private name: string, + private definition: Document, + override options: Document + ) { + super(options); + } + + execute(server: Server, session: ClientSession | undefined, callback: Callback): void { + const namespace = this.collection.mongoDBNamespace; + const command = { + updateSearchIndex: namespace.collection, + name: this.name, + definition: this.definition + }; + + server.command(namespace, command, { session }, err => { + if (err) { + callback(err); + return; + } + + callback(); + }); + } +} diff --git a/src/utils.ts b/src/utils.ts index 23debd74e82..8d2746edf13 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -321,8 +321,8 @@ export class MongoDBNamespace { return this.collection ? `${this.db}.${this.collection}` : this.db; } - withCollection(collection: string): MongoDBNamespace { - return new MongoDBNamespace(this.db, collection); + withCollection(collection: string): MongoDBCollectionNamespace { + return new MongoDBCollectionNamespace(this.db, collection); } static fromString(namespace?: string): MongoDBNamespace { @@ -337,6 +337,17 @@ export class MongoDBNamespace { } } +/** + * @public + * + * A class representing a collection's namespace. + */ +export class MongoDBCollectionNamespace extends MongoDBNamespace { + constructor(db: string, override collection: string) { + super(db, collection); + } +} + /** @internal */ export function* makeCounter(seed = 0): Generator { let count = seed; From 6f9ab16700e11f38e30457824c814ab597ae896b Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 16 May 2023 11:56:12 -0600 Subject: [PATCH 02/24] add index management tests --- src/operations/search_indexes/list.ts | 3 +- .../index-management.spec.test.ts | 8 + test/spec/index-management/README.rst | 48 ++++++ .../index-management/createSearchIndexes.json | 154 ++++++++++++++++++ .../index-management/createSearchIndexes.yml | 79 +++++++++ .../index-management/dropSearchIndexes.json | 78 +++++++++ .../index-management/dropSearchIndexes.yml | 44 +++++ .../index-management/listSearchIndexes.json | 118 ++++++++++++++ .../index-management/listSearchIndexes.yml | 64 ++++++++ .../index-management/updateSearchIndex.json | 80 +++++++++ .../index-management/updateSearchIndex.yml | 46 ++++++ test/tools/unified-spec-runner/operations.ts | 24 +++ 12 files changed, 745 insertions(+), 1 deletion(-) create mode 100644 test/integration/index-management/index-management.spec.test.ts create mode 100644 test/spec/index-management/README.rst create mode 100644 test/spec/index-management/createSearchIndexes.json create mode 100644 test/spec/index-management/createSearchIndexes.yml create mode 100644 test/spec/index-management/dropSearchIndexes.json create mode 100644 test/spec/index-management/dropSearchIndexes.yml create mode 100644 test/spec/index-management/listSearchIndexes.json create mode 100644 test/spec/index-management/listSearchIndexes.yml create mode 100644 test/spec/index-management/updateSearchIndex.json create mode 100644 test/spec/index-management/updateSearchIndex.yml diff --git a/src/operations/search_indexes/list.ts b/src/operations/search_indexes/list.ts index 35fb0cac99a..fec04f43bc3 100644 --- a/src/operations/search_indexes/list.ts +++ b/src/operations/search_indexes/list.ts @@ -13,7 +13,8 @@ export class ListSearchIndexesCursor extends AggregationCursor<{ name: string }> ): ListSearchIndexesCursor { const client = collection.client; const ns = collection.mongoDBNamespace; - const pipeline = name == null ? [{ $listIndexes: {} }] : [{ $listSearchIndexes: { name } }]; + const pipeline = + name == null ? [{ $listSearchIndexes: {} }] : [{ $listSearchIndexes: { name } }]; return new ListSearchIndexesCursor(client, ns, pipeline, options); } } diff --git a/test/integration/index-management/index-management.spec.test.ts b/test/integration/index-management/index-management.spec.test.ts new file mode 100644 index 00000000000..2343ee02d6f --- /dev/null +++ b/test/integration/index-management/index-management.spec.test.ts @@ -0,0 +1,8 @@ +import { join } from 'path'; + +import { loadSpecTests } from '../../spec'; +import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; + +describe.only('Index Management Tests (Unified)', function () { + runUnifiedSuite(loadSpecTests(join('index-management'))); +}); diff --git a/test/spec/index-management/README.rst b/test/spec/index-management/README.rst new file mode 100644 index 00000000000..e697dab3480 --- /dev/null +++ b/test/spec/index-management/README.rst @@ -0,0 +1,48 @@ +====================== +Index Management Tests +====================== + +.. contents:: + +---- + +Test Plan +========= + +These prose tests are ported from the legacy enumerate-indexes spec. + +Configurations +-------------- + +- standalone node +- replica set primary node +- replica set secondary node +- mongos node + +Preparation +----------- + +For each of the configurations: + +- Create a (new) database +- Create a collection +- Create a single column index, a compound index, and a unique index +- Insert at least one document containing all the fields that the above + indicated indexes act on + +Tests +----- + +- Run the driver's method that returns a list of index names, and: + + - verify that *all* index names are represented in the result + - verify that there are no duplicate index names + - verify there are no returned indexes that do not exist + +- Run the driver's method that returns a list of index information records, and: + + - verify all the indexes are represented in the result + - verify the "unique" flags show up for the unique index + - verify there are no duplicates in the returned list + - if the result consists of statically defined index models that include an ``ns`` field, verify + that its value is accurate \ No newline at end of file diff --git a/test/spec/index-management/createSearchIndexes.json b/test/spec/index-management/createSearchIndexes.json new file mode 100644 index 00000000000..dd0f0a05aca --- /dev/null +++ b/test/spec/index-management/createSearchIndexes.json @@ -0,0 +1,154 @@ +{ + "description": "createSearchIndexes", + "schemaVersion": "1.10", + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "database0" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "collection0" + } + } + ], + "runOnRequirements": [ + { + "minServerVersion": "4.0.0", + "topologies": [ + "replicaset", + "load-balanced", + "sharded" + ], + "serverless": "forbid" + } + ], + "initialData": [ + { + "collectionName": "collection0", + "databaseName": "database0", + "documents": [] + } + ], + "tests": [ + { + "description": "empty index definition array", + "operations": [ + { + "name": "createSearchIndexes", + "object": "collection0", + "arguments": { + "indexDefinitions": [] + }, + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "createSearchIndexes": "collection0", + "indexes": [] + } + } + } + ] + } + ] + }, + { + "description": "no name provided for an index definition", + "operations": [ + { + "name": "createSearchIndexes", + "object": "collection0", + "arguments": { + "indexDefinitions": [ + { + "definition": {} + } + ] + }, + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "createSearchIndexes": "collection0", + "indexes": [ + { + "definition": {} + } + ] + } + } + } + ] + } + ] + }, + { + "description": "name provided for an index definition", + "operations": [ + { + "name": "createSearchIndexes", + "object": "collection0", + "arguments": { + "indexDefinitions": [ + { + "definition": {}, + "name": "test index" + } + ] + }, + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "createSearchIndexes": "collection0", + "indexes": [ + { + "definition": {}, + "name": "test index" + } + ] + } + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/index-management/createSearchIndexes.yml b/test/spec/index-management/createSearchIndexes.yml new file mode 100644 index 00000000000..4117a5491cd --- /dev/null +++ b/test/spec/index-management/createSearchIndexes.yml @@ -0,0 +1,79 @@ +description: "createSearchIndexes" +schemaVersion: "1.10" +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + observeEvents: + - commandStartedEvent + - database: + id: &database0 database0 + client: *client0 + databaseName: *database0 + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: *collection0 + +runOnRequirements: + - minServerVersion: "4.0.0" + topologies: [ replicaset, load-balanced, sharded ] + serverless: forbid + +initialData: + # create the conection initially + - collectionName: *collection0 + databaseName: *database0 + documents: [] + +tests: + - description: "empty index definition array" + operations: + - name: createSearchIndexes + object: *collection0 + arguments: + indexDefinitions: [] + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + createSearchIndexes: *collection0 + indexes: [] + + - description: "no name provided for an index definition" + operations: + - name: createSearchIndexes + object: *collection0 + arguments: + indexDefinitions: [ { definition: {} } ] + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + createSearchIndexes: *collection0 + indexes: [ { definition: {} } ] + + - description: "name provided for an index definition" + operations: + - name: createSearchIndexes + object: *collection0 + arguments: + indexDefinitions: [ { definition: {}, name: 'test index' } ] + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + createSearchIndexes: *collection0 + indexes: [ { definition: {}, name: 'test index' } ] + + + \ No newline at end of file diff --git a/test/spec/index-management/dropSearchIndexes.json b/test/spec/index-management/dropSearchIndexes.json new file mode 100644 index 00000000000..6cd0cf4d2dd --- /dev/null +++ b/test/spec/index-management/dropSearchIndexes.json @@ -0,0 +1,78 @@ +{ + "description": "dropSearchIndexes", + "schemaVersion": "1.10", + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "database0" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "collection0" + } + } + ], + "runOnRequirements": [ + { + "minServerVersion": "4.0.0", + "topologies": [ + "replicaset", + "load-balanced", + "sharded" + ], + "serverless": "forbid" + } + ], + "initialData": [ + { + "collectionName": "collection0", + "databaseName": "database0", + "documents": [] + } + ], + "tests": [ + { + "description": "sends the correct command", + "operations": [ + { + "name": "dropSearchIndex", + "object": "collection0", + "arguments": { + "indexName": "test index" + }, + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "dropSearchIndex": "collection0", + "name": "test index" + } + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/index-management/dropSearchIndexes.yml b/test/spec/index-management/dropSearchIndexes.yml new file mode 100644 index 00000000000..435fd152bd0 --- /dev/null +++ b/test/spec/index-management/dropSearchIndexes.yml @@ -0,0 +1,44 @@ +description: "dropSearchIndexes" +schemaVersion: "1.10" +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + observeEvents: + - commandStartedEvent + - database: + id: &database0 database0 + client: *client0 + databaseName: *database0 + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: *collection0 + +runOnRequirements: + - minServerVersion: "4.0.0" + topologies: [ replicaset, load-balanced, sharded ] + serverless: forbid + +initialData: + # create the conection initially + - collectionName: *collection0 + databaseName: *database0 + documents: [] + +tests: + - description: "sends the correct command" + operations: + - name: dropSearchIndex + object: *collection0 + arguments: + indexName: &indexName 'test index' + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + dropSearchIndex: *collection0 + name: *indexName diff --git a/test/spec/index-management/listSearchIndexes.json b/test/spec/index-management/listSearchIndexes.json new file mode 100644 index 00000000000..28b1c9d06ec --- /dev/null +++ b/test/spec/index-management/listSearchIndexes.json @@ -0,0 +1,118 @@ +{ + "description": "listSearchIndexes", + "schemaVersion": "1.10", + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "database0" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "collection0" + } + } + ], + "runOnRequirements": [ + { + "minServerVersion": "4.0.0", + "topologies": [ + "replicaset", + "load-balanced", + "sharded" + ], + "serverless": "forbid" + } + ], + "initialData": [ + { + "collectionName": "collection0", + "databaseName": "database0", + "documents": [] + } + ], + "tests": [ + { + "description": "when no name is provided, it does not populate the filter", + "operations": [ + { + "name": "listSearchIndexes", + "object": "collection0", + "arguments": [], + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "collection0", + "pipeline": [ + { + "$listSearchIndexes": {} + } + ] + } + } + } + ] + } + ] + }, + { + "description": "when a name is provided, it is present in the filter", + "operations": [ + { + "name": "listSearchIndexes", + "object": "collection0", + "arguments": { + "indexName": "test index" + }, + "saveResultAsEntity": "changeStream0", + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "collection0", + "pipeline": [ + { + "$$matchAsRoot": { + "$listSearchIndexes": { + "name": "test index" + } + } + } + ] + } + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/index-management/listSearchIndexes.yml b/test/spec/index-management/listSearchIndexes.yml new file mode 100644 index 00000000000..3f012ac2c0b --- /dev/null +++ b/test/spec/index-management/listSearchIndexes.yml @@ -0,0 +1,64 @@ +description: "listSearchIndexes" +schemaVersion: "1.10" +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + observeEvents: + - commandStartedEvent + - database: + id: &database0 database0 + client: *client0 + databaseName: *database0 + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: *collection0 + +runOnRequirements: + - minServerVersion: "4.0.0" + topologies: [ replicaset, load-balanced, sharded ] + serverless: forbid + +initialData: + # create the conection initially + - collectionName: *collection0 + databaseName: *database0 + documents: [] + +tests: + - description: "when no name is provided, it does not populate the filter" + operations: + - name: listSearchIndexes + object: *collection0 + arguments: [] + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + aggregate: *collection0 + pipeline: + - $listSearchIndexes: {} + + - description: "when a name is provided, it is present in the filter" + operations: + - name: listSearchIndexes + object: *collection0 + arguments: + indexName: &indexName "test index" + saveResultAsEntity: &changeStream0 changeStream0 + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + aggregate: *collection0 + pipeline: + - $$matchAsRoot: + $listSearchIndexes: + { name: *indexName } \ No newline at end of file diff --git a/test/spec/index-management/updateSearchIndex.json b/test/spec/index-management/updateSearchIndex.json new file mode 100644 index 00000000000..ac26b9d7fe2 --- /dev/null +++ b/test/spec/index-management/updateSearchIndex.json @@ -0,0 +1,80 @@ +{ + "description": "updateSearchIndex", + "schemaVersion": "1.10", + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "database0" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "collection0" + } + } + ], + "runOnRequirements": [ + { + "minServerVersion": "4.0.0", + "topologies": [ + "replicaset", + "load-balanced", + "sharded" + ], + "serverless": "forbid" + } + ], + "initialData": [ + { + "collectionName": "collection0", + "databaseName": "database0", + "documents": [] + } + ], + "tests": [ + { + "description": "sends the correct command", + "operations": [ + { + "name": "updateSearchIndex", + "object": "collection0", + "arguments": { + "indexName": "test index", + "definition": {} + }, + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "updateSearchIndex": "collection0", + "name": "test index", + "definition": {} + } + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/index-management/updateSearchIndex.yml b/test/spec/index-management/updateSearchIndex.yml new file mode 100644 index 00000000000..750de26bb24 --- /dev/null +++ b/test/spec/index-management/updateSearchIndex.yml @@ -0,0 +1,46 @@ +description: "updateSearchIndex" +schemaVersion: "1.10" +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + observeEvents: + - commandStartedEvent + - database: + id: &database0 database0 + client: *client0 + databaseName: *database0 + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: *collection0 + +runOnRequirements: + - minServerVersion: "4.0.0" + topologies: [ replicaset, load-balanced, sharded ] + serverless: forbid + +initialData: + # create the conection initially + - collectionName: *collection0 + databaseName: *database0 + documents: [] + +tests: + - description: "sends the correct command" + operations: + - name: updateSearchIndex + object: *collection0 + arguments: + indexName: &indexName 'test index' + definition: &definition {} + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + updateSearchIndex: *collection0 + name: *indexName + definition: *definition diff --git a/test/tools/unified-spec-runner/operations.ts b/test/tools/unified-spec-runner/operations.ts index 3118a518897..ef418629988 100644 --- a/test/tools/unified-spec-runner/operations.ts +++ b/test/tools/unified-spec-runner/operations.ts @@ -753,6 +753,30 @@ operations.set('getKeyByAltName', async ({ entities, operation }) => { return clientEncryption.getKeyByAltName(keyAltName); }); +operations.set('listSearchIndexes', async ({ entities, operation }) => { + const collection: Collection = entities.getEntity('collection', operation.object); + const { indexName } = operation.arguments!; + return collection.listSearchIndexes(indexName).toArray(); +}); + +operations.set('dropSearchIndex', async ({ entities, operation }) => { + const collection: Collection = entities.getEntity('collection', operation.object); + const { indexName } = operation.arguments!; + return collection.dropSearchIndex(indexName); +}); + +operations.set('updateSearchIndex', async ({ entities, operation }) => { + const collection: Collection = entities.getEntity('collection', operation.object); + const { indexName, definition } = operation.arguments!; + return collection.updateSearchIndex(indexName, definition); +}); + +operations.set('createSearchIndexes', async ({ entities, operation }) => { + const collection: Collection = entities.getEntity('collection', operation.object); + const { indexDefinitions } = operation.arguments!; + return collection.createSearchIndexes(indexDefinitions); +}); + export async function executeOperationAndCheck( operation: OperationDescription, entities: EntitiesMap, From 2849b11c92b94ed1e5ee8857475530c2cfdeb176 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 16 May 2023 13:18:02 -0600 Subject: [PATCH 03/24] scaffolding initial rn --- .evergreen/config.in.yml | 8 ++++--- .evergreen/config.yml | 21 ++++++++++++++++-- .evergreen/generate_evergreen_tasks.js | 22 +++++++++++++++++++ .../run-search-index-management-tests.sh | 3 +++ package.json | 3 ++- .../index-management.spec.test.ts | 2 +- 6 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 .evergreen/run-search-index-management-tests.sh diff --git a/.evergreen/config.in.yml b/.evergreen/config.in.yml index df9142ffa80..b1a2ad2a835 100644 --- a/.evergreen/config.in.yml +++ b/.evergreen/config.in.yml @@ -40,10 +40,12 @@ functions: args: - .evergreen/prepare-shell.sh - # Load the expansion file to make an evergreen variable with the current unique version - - command: expansions.update + "run search index management tests": + - command: subprocess.exec params: - file: src/expansion.yml + binary: bash + args: + - src/.evergreen/run-search-index-management-tests.sh "bootstrap mongo-orchestration": - command: subprocess.exec diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 925f5a40e8a..849f0c736c4 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -22,9 +22,12 @@ functions: project: ${project} args: - .evergreen/prepare-shell.sh - - command: expansions.update +ev run search index management tests: + - command: subprocess.exec params: - file: src/expansion.yml + binary: bash + args: + - src/.evergreen/run-search-index-management-tests.sh bootstrap mongo-orchestration: - command: subprocess.exec params: @@ -2589,6 +2592,15 @@ tasks: variant: '*' status: '*' patch_optional: true + - name: test-search-index-helpers + tags: [] + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: latest + TOPOLOGY: replica_set + - func: run search index management tests - name: run-custom-csfle-tests-5.0-pinned-commit tags: - run-custom-dependency-tests @@ -4001,3 +4013,8 @@ buildvariants: - test-lambda-example - test-lambda-aws-auth-example - test-deployed-lambda + - name: rhel8-test-seach-index-management-helpers + display_name: Search Index Management Helpers Tests + run_on: rhel80-large + tasks: + - test-search-index-helpers diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index f15b84b24be..18ee4e7035c 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -699,6 +699,21 @@ const coverageTask = { }; SINGLETON_TASKS.push(coverageTask); +SINGLETON_TASKS.push({ + name: 'test-search-index-helpers', + tags: [], + commands: [ + { func: 'install dependencies' }, + { + func: 'bootstrap mongo-orchestration', + vars: { + VERSION: 'latest', + TOPOLOGY: 'replica_set' + } + }, + { func: 'run search index management tests' } + ] +}) SINGLETON_TASKS.push(...oneOffFuncAsTasks); BUILD_VARIANTS.push({ @@ -751,6 +766,13 @@ BUILD_VARIANTS.push({ tasks: ['test-lambda-example', 'test-lambda-aws-auth-example', 'test-deployed-lambda'] }); +BUILD_VARIANTS.push({ + name: 'rhel8-test-seach-index-management-helpers', + display_name: 'Search Index Management Helpers Tests', + run_on: DEFAULT_OS, + tasks: ['test-search-index-helpers'] +}) + // TODO(NODE-4575): unskip zstd and snappy on node 16 for (const variant of BUILD_VARIANTS.filter( variant => diff --git a/.evergreen/run-search-index-management-tests.sh b/.evergreen/run-search-index-management-tests.sh new file mode 100644 index 00000000000..b951f9aea08 --- /dev/null +++ b/.evergreen/run-search-index-management-tests.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +npm run check:search-indexes diff --git a/package.json b/package.json index 264b14268fd..1faf5ef3dbb 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,8 @@ "check:tsd": "tsd --version && tsd", "check:dependencies": "mocha test/action/dependency.test.ts", "check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd", - "check:test": "mocha --config test/mocha_mongodb.json test/integration", + "check:search-indexes": "mocha --config test/mocha_mongodb.json test/integration/index-management", + "check:test": "mocha --config test/mocha_mongodb.json --exclude test/integration/index-management/**ts test/integration", "check:unit": "mocha test/unit", "check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit", "check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js", diff --git a/test/integration/index-management/index-management.spec.test.ts b/test/integration/index-management/index-management.spec.test.ts index 2343ee02d6f..3f1c9ae57a9 100644 --- a/test/integration/index-management/index-management.spec.test.ts +++ b/test/integration/index-management/index-management.spec.test.ts @@ -3,6 +3,6 @@ import { join } from 'path'; import { loadSpecTests } from '../../spec'; import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; -describe.only('Index Management Tests (Unified)', function () { +describe('Index Management Tests (Unified)', function () { runUnifiedSuite(loadSpecTests(join('index-management'))); }); From 65c54063214a9011b434ee0769078a8f82059722 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 16 May 2023 15:38:09 -0600 Subject: [PATCH 04/24] CI passing --- .evergreen/config.in.yml | 9 ++++++++- .evergreen/config.yml | 11 +++++++++-- .evergreen/generate_evergreen_tasks.js | 7 ++++++- .evergreen/run-search-index-management-tests.sh | 2 ++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.evergreen/config.in.yml b/.evergreen/config.in.yml index b1a2ad2a835..07836f9b234 100644 --- a/.evergreen/config.in.yml +++ b/.evergreen/config.in.yml @@ -40,12 +40,19 @@ functions: args: - .evergreen/prepare-shell.sh + # Load the expansion file to make an evergreen variable with the current unique version + - command: expansions.update + params: + file: src/expansion.yml + "run search index management tests": - command: subprocess.exec params: binary: bash + working_dir: src + add_expansions_to_env: true args: - - src/.evergreen/run-search-index-management-tests.sh + - .evergreen/run-search-index-management-tests.sh "bootstrap mongo-orchestration": - command: subprocess.exec diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 849f0c736c4..7be9befa70f 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -22,12 +22,17 @@ functions: project: ${project} args: - .evergreen/prepare-shell.sh -ev run search index management tests: + - command: expansions.update + params: + file: src/expansion.yml + run search index management tests: - command: subprocess.exec params: binary: bash + working_dir: src + add_expansions_to_env: true args: - - src/.evergreen/run-search-index-management-tests.sh + - .evergreen/run-search-index-management-tests.sh bootstrap mongo-orchestration: - command: subprocess.exec params: @@ -2596,6 +2601,8 @@ tasks: tags: [] commands: - func: install dependencies + vars: + NODE_LTS_NAME: hydrogen - func: bootstrap mongo-orchestration vars: VERSION: latest diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 18ee4e7035c..78f660cc3cf 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -703,7 +703,12 @@ SINGLETON_TASKS.push({ name: 'test-search-index-helpers', tags: [], commands: [ - { func: 'install dependencies' }, + { + func: 'install dependencies', + vars: { + NODE_LTS_NAME: LATEST_LTS + } + }, { func: 'bootstrap mongo-orchestration', vars: { diff --git a/.evergreen/run-search-index-management-tests.sh b/.evergreen/run-search-index-management-tests.sh index b951f9aea08..825e5732adf 100644 --- a/.evergreen/run-search-index-management-tests.sh +++ b/.evergreen/run-search-index-management-tests.sh @@ -1,3 +1,5 @@ #! /bin/bash +source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" + npm run check:search-indexes From 7802d26075f9df2b262afad83ad49fdc42e2458d Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 17 May 2023 08:53:48 -0600 Subject: [PATCH 05/24] node changes done --- src/collection.ts | 51 +++++++++++++------------ src/index.ts | 6 +++ src/operations/search_indexes/create.ts | 12 ++++-- src/operations/search_indexes/drop.ts | 10 ++--- src/operations/search_indexes/list.ts | 10 +++-- src/operations/search_indexes/update.ts | 7 ++-- src/utils.ts | 9 ++--- 7 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/collection.ts b/src/collection.ts index 744b83af6b6..bdcfbf72d17 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -206,11 +206,15 @@ export class Collection { * The namespace of this collection, in the format `${this.dbName}.${this.collectionName}` */ get namespace(): string { - return this.mongoDBNamespace.toString(); + return this.fullNamespace.toString(); } - /** @internal */ - get mongoDBNamespace(): MongoDBCollectionNamespace { + /** + * @internal + * + * The `MongoDBNamespace` for the collection. + */ + get fullNamespace(): MongoDBCollectionNamespace { return this.s.namespace; } @@ -995,51 +999,50 @@ export class Collection { async count(filter: Filter = {}, options: CountOptions = {}): Promise { return executeOperation( this.s.db.s.client, - new CountOperation(this.mongoDBNamespace, filter, resolveOptions(this, options)) + new CountOperation(this.fullNamespace, filter, resolveOptions(this, options)) ); } listSearchIndexes(options?: ListSearchIndexesOptions): ListSearchIndexesCursor; listSearchIndexes(indexName: string, options?: ListSearchIndexesOptions): ListSearchIndexesCursor; listSearchIndexes( - indexName?: string | ListSearchIndexesOptions, + indexNameOrOptions?: string | ListSearchIndexesOptions, options?: ListSearchIndexesOptions ): ListSearchIndexesCursor { - // todo: options handling - - return ListSearchIndexesCursor.create(this, indexName as any, options); + options = + typeof indexNameOrOptions === 'object' ? indexNameOrOptions : options == null ? {} : options; + const indexName = + indexNameOrOptions == null + ? null + : typeof indexNameOrOptions === 'object' + ? null + : indexNameOrOptions; + + return ListSearchIndexesCursor.create(this, indexName, options); } - async createSearchIndex( - description: SearchIndexDescription, - options: Document = {} - ): Promise { - const indexes = await this.createSearchIndexes([description], options); + async createSearchIndex(description: SearchIndexDescription): Promise { + const indexes = await this.createSearchIndexes([description]); return indexes[0]; } async createSearchIndexes( - descriptions: ReadonlyArray, - options: Document = {} + descriptions: ReadonlyArray ): Promise { return executeOperation( this.s.db.s.client, - new CreateSearchIndexesOperation(this, descriptions, options) + new CreateSearchIndexesOperation(this, descriptions) ); } - async dropSearchIndex(name: string, options: Document = {}): Promise { - return executeOperation(this.s.db.s.client, new DropSearchIndexOperation(this, name, options)); + async dropSearchIndex(name: string): Promise { + return executeOperation(this.s.db.s.client, new DropSearchIndexOperation(this, name)); } - async updateSearchIndex( - name: string, - definition: Document, - options: Document = {} - ): Promise { + async updateSearchIndex(name: string, definition: Document): Promise { return executeOperation( this.s.db.s.client, - new UpdateSearchIndexOperation(this, name, definition, options) + new UpdateSearchIndexOperation(this, name, definition) ); } } diff --git a/src/index.ts b/src/index.ts index 7917e235390..377216bb42b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -418,6 +418,11 @@ export type { ProfilingLevelOptions } from './operations/profiling_level'; export type { RemoveUserOptions } from './operations/remove_user'; export type { RenameOptions } from './operations/rename'; export type { RunCommandOptions } from './operations/run_command'; +export type { SearchIndexDescription } from './operations/search_indexes/create'; +export type { + ListSearchIndexesCursor, + ListSearchIndexesOptions +} from './operations/search_indexes/list'; export type { SetProfilingLevelOptions } from './operations/set_profiling_level'; export type { CollStats, @@ -489,6 +494,7 @@ export type { EventEmitterWithState, HostAddress, List, + MongoDBCollectionNamespace, MongoDBNamespace } from './utils'; export type { W, WriteConcernOptions, WriteConcernSettings } from './write_concern'; diff --git a/src/operations/search_indexes/create.ts b/src/operations/search_indexes/create.ts index 5960231d119..ca84dec84b3 100644 --- a/src/operations/search_indexes/create.ts +++ b/src/operations/search_indexes/create.ts @@ -6,22 +6,26 @@ import type { ClientSession } from '../../sessions'; import type { Callback } from '../../utils'; import { AbstractOperation } from '../operation'; +/** @public */ export interface SearchIndexDescription { + /** The name of the index. */ name?: string; + + /** The index definition. */ description: Document; } +/** @internal */ export class CreateSearchIndexesOperation extends AbstractOperation { constructor( private collection: Collection, - private descriptions: ReadonlyArray, - override options: Document = {} + private descriptions: ReadonlyArray ) { - super(options); + super(); } execute(server: Server, session: ClientSession | undefined, callback: Callback): void { - const namespace = this.collection.mongoDBNamespace; + const namespace = this.collection.fullNamespace; const command = { createSearchIndexes: namespace.collection, indexes: this.descriptions diff --git a/src/operations/search_indexes/drop.ts b/src/operations/search_indexes/drop.ts index 87aeb764355..c8e7755ccd3 100644 --- a/src/operations/search_indexes/drop.ts +++ b/src/operations/search_indexes/drop.ts @@ -8,16 +8,12 @@ import { AbstractOperation } from '../operation'; export class DropSearchIndexOperation extends AbstractOperation { /** @internal */ - constructor( - private collection: Collection, - private name: string, - override options: Document = {} - ) { - super(options); + constructor(private collection: Collection, private name: string) { + super(); } execute(server: Server, session: ClientSession | undefined, callback: Callback): void { - const namespace = this.collection.mongoDBNamespace; + const namespace = this.collection.fullNamespace; const command: Document = { dropSearchIndex: namespace.collection diff --git a/src/operations/search_indexes/list.ts b/src/operations/search_indexes/list.ts index fec04f43bc3..0bf537878f3 100644 --- a/src/operations/search_indexes/list.ts +++ b/src/operations/search_indexes/list.ts @@ -1,18 +1,20 @@ +import type { Document } from 'bson'; + import type { Collection } from '../../collection'; import { AggregationCursor } from '../../cursor/aggregation_cursor'; import type { AggregateOptions } from '../aggregate'; +/** @public */ export type ListSearchIndexesOptions = AggregateOptions; +/** @public */ export class ListSearchIndexesCursor extends AggregationCursor<{ name: string }> { /** @internal */ - static create( - collection: Collection, + static create( + { fullNamespace: ns, client }: Collection, name: string | null, options: ListSearchIndexesOptions = {} ): ListSearchIndexesCursor { - const client = collection.client; - const ns = collection.mongoDBNamespace; const pipeline = name == null ? [{ $listSearchIndexes: {} }] : [{ $listSearchIndexes: { name } }]; return new ListSearchIndexesCursor(client, ns, pipeline, options); diff --git a/src/operations/search_indexes/update.ts b/src/operations/search_indexes/update.ts index 08586c6dde0..4317050e0ea 100644 --- a/src/operations/search_indexes/update.ts +++ b/src/operations/search_indexes/update.ts @@ -10,14 +10,13 @@ export class UpdateSearchIndexOperation extends AbstractOperation { constructor( private collection: Collection, private name: string, - private definition: Document, - override options: Document + private definition: Document ) { - super(options); + super(); } execute(server: Server, session: ClientSession | undefined, callback: Callback): void { - const namespace = this.collection.mongoDBNamespace; + const namespace = this.collection.fullNamespace; const command = { updateSearchIndex: namespace.collection, name: this.name, diff --git a/src/utils.ts b/src/utils.ts index 8d2746edf13..d61f4c0f426 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -304,16 +304,13 @@ export function ns(ns: string): MongoDBNamespace { /** @public */ export class MongoDBNamespace { - db: string; - collection: string | undefined; /** * Create a namespace object * * @param db - database name * @param collection - collection name */ - constructor(db: string, collection?: string) { - this.db = db; + constructor(public db: string, public collection?: string) { this.collection = collection === '' ? undefined : collection; } @@ -340,7 +337,9 @@ export class MongoDBNamespace { /** * @public * - * A class representing a collection's namespace. + * A class representing a collection's namespace. This class enforces that + * the `collection` portion of the namespace is defined and should only be + * used in scenarios where this can be guaranteed. */ export class MongoDBCollectionNamespace extends MongoDBNamespace { constructor(db: string, override collection: string) { From bdb14b288b48a2f092dfcccb4c3a2ed3f78a32f1 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 17 May 2023 11:28:18 -0600 Subject: [PATCH 06/24] make fields readonly --- src/operations/search_indexes/create.ts | 4 ++-- src/operations/search_indexes/drop.ts | 2 +- src/operations/search_indexes/update.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/operations/search_indexes/create.ts b/src/operations/search_indexes/create.ts index ca84dec84b3..121acab1273 100644 --- a/src/operations/search_indexes/create.ts +++ b/src/operations/search_indexes/create.ts @@ -18,8 +18,8 @@ export interface SearchIndexDescription { /** @internal */ export class CreateSearchIndexesOperation extends AbstractOperation { constructor( - private collection: Collection, - private descriptions: ReadonlyArray + private readonly collection: Collection, + private readonly descriptions: ReadonlyArray ) { super(); } diff --git a/src/operations/search_indexes/drop.ts b/src/operations/search_indexes/drop.ts index c8e7755ccd3..27c4898a140 100644 --- a/src/operations/search_indexes/drop.ts +++ b/src/operations/search_indexes/drop.ts @@ -8,7 +8,7 @@ import { AbstractOperation } from '../operation'; export class DropSearchIndexOperation extends AbstractOperation { /** @internal */ - constructor(private collection: Collection, private name: string) { + constructor(private readonly collection: Collection, private readonly name: string) { super(); } diff --git a/src/operations/search_indexes/update.ts b/src/operations/search_indexes/update.ts index 4317050e0ea..4875eeb576c 100644 --- a/src/operations/search_indexes/update.ts +++ b/src/operations/search_indexes/update.ts @@ -8,9 +8,9 @@ import { AbstractOperation } from '../operation'; export class UpdateSearchIndexOperation extends AbstractOperation { constructor( - private collection: Collection, - private name: string, - private definition: Document + private readonly collection: Collection, + private readonly name: string, + private readonly definition: Document ) { super(); } From e8ef3749f7ea22a83452e8d41ae3ee3ff55d3ed0 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 17 May 2023 14:39:36 -0600 Subject: [PATCH 07/24] misc test updates --- .../index-management/createSearchIndex.json | 114 ++++++++++++++++++ .../index-management/createSearchIndex.yml | 57 +++++++++ .../index-management/createSearchIndexes.json | 9 +- .../index-management/createSearchIndexes.yml | 10 +- .../index-management/dropSearchIndexes.json | 9 +- .../index-management/dropSearchIndexes.yml | 8 +- .../index-management/listSearchIndexes.json | 53 ++++++-- .../index-management/listSearchIndexes.yml | 31 +++-- .../index-management/updateSearchIndex.json | 9 +- .../index-management/updateSearchIndex.yml | 8 +- test/tools/unified-spec-runner/operations.ts | 12 +- 11 files changed, 256 insertions(+), 64 deletions(-) create mode 100644 test/spec/index-management/createSearchIndex.json create mode 100644 test/spec/index-management/createSearchIndex.yml diff --git a/test/spec/index-management/createSearchIndex.json b/test/spec/index-management/createSearchIndex.json new file mode 100644 index 00000000000..56b65939820 --- /dev/null +++ b/test/spec/index-management/createSearchIndex.json @@ -0,0 +1,114 @@ +{ + "description": "createSearchIndex convenience helper", + "schemaVersion": "1.10", + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "database0" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "collection0" + } + } + ], + "runOnRequirements": [ + { + "minServerVersion": "7.0.0", + "topologies": [ + "replicaset", + "load-balanced", + "sharded" + ], + "serverless": "forbid" + } + ], + "tests": [ + { + "description": "no name provided for an index definition", + "operations": [ + { + "name": "createSearchIndex", + "object": "collection0", + "arguments": { + "definition": { + "definition": {} + } + }, + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "createSearchIndexes": "collection0", + "indexes": [ + { + "definition": {} + } + ] + } + } + } + ] + } + ] + }, + { + "description": "name provided for an index definition", + "operations": [ + { + "name": "createSearchIndex", + "object": "collection0", + "arguments": { + "definition": { + "definition": {}, + "name": "test index" + } + }, + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "createSearchIndexes": "collection0", + "indexes": [ + { + "definition": {}, + "name": "test index" + } + ] + } + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/index-management/createSearchIndex.yml b/test/spec/index-management/createSearchIndex.yml new file mode 100644 index 00000000000..b9fa6cbf900 --- /dev/null +++ b/test/spec/index-management/createSearchIndex.yml @@ -0,0 +1,57 @@ +description: "createSearchIndex convenience helper" +schemaVersion: "1.10" +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + observeEvents: + - commandStartedEvent + - database: + id: &database0 database0 + client: *client0 + databaseName: *database0 + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: *collection0 + +runOnRequirements: + - minServerVersion: "7.0.0" + topologies: [ replicaset, load-balanced, sharded ] + serverless: forbid + +tests: + - description: "no name provided for an index definition" + operations: + - name: createSearchIndex + object: *collection0 + arguments: + definition: { definition: {} } + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + createSearchIndexes: *collection0 + indexes: [ { definition: {} } ] + + - description: "name provided for an index definition" + operations: + - name: createSearchIndex + object: *collection0 + arguments: + definition: { definition: {}, name: 'test index' } + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + createSearchIndexes: *collection0 + indexes: [ { definition: {}, name: 'test index' } ] + + + \ No newline at end of file diff --git a/test/spec/index-management/createSearchIndexes.json b/test/spec/index-management/createSearchIndexes.json index dd0f0a05aca..a47b68e3cb5 100644 --- a/test/spec/index-management/createSearchIndexes.json +++ b/test/spec/index-management/createSearchIndexes.json @@ -28,7 +28,7 @@ ], "runOnRequirements": [ { - "minServerVersion": "4.0.0", + "minServerVersion": "7.0.0", "topologies": [ "replicaset", "load-balanced", @@ -37,13 +37,6 @@ "serverless": "forbid" } ], - "initialData": [ - { - "collectionName": "collection0", - "databaseName": "database0", - "documents": [] - } - ], "tests": [ { "description": "empty index definition array", diff --git a/test/spec/index-management/createSearchIndexes.yml b/test/spec/index-management/createSearchIndexes.yml index 4117a5491cd..2482fa0723f 100644 --- a/test/spec/index-management/createSearchIndexes.yml +++ b/test/spec/index-management/createSearchIndexes.yml @@ -16,16 +16,10 @@ createEntities: collectionName: *collection0 runOnRequirements: - - minServerVersion: "4.0.0" + - minServerVersion: "7.0.0" topologies: [ replicaset, load-balanced, sharded ] serverless: forbid -initialData: - # create the conection initially - - collectionName: *collection0 - databaseName: *database0 - documents: [] - tests: - description: "empty index definition array" operations: @@ -47,7 +41,7 @@ tests: operations: - name: createSearchIndexes object: *collection0 - arguments: + arguments: indexDefinitions: [ { definition: {} } ] expectError: {} expectEvents: diff --git a/test/spec/index-management/dropSearchIndexes.json b/test/spec/index-management/dropSearchIndexes.json index 6cd0cf4d2dd..87854300a70 100644 --- a/test/spec/index-management/dropSearchIndexes.json +++ b/test/spec/index-management/dropSearchIndexes.json @@ -28,7 +28,7 @@ ], "runOnRequirements": [ { - "minServerVersion": "4.0.0", + "minServerVersion": "7.0.0", "topologies": [ "replicaset", "load-balanced", @@ -37,13 +37,6 @@ "serverless": "forbid" } ], - "initialData": [ - { - "collectionName": "collection0", - "databaseName": "database0", - "documents": [] - } - ], "tests": [ { "description": "sends the correct command", diff --git a/test/spec/index-management/dropSearchIndexes.yml b/test/spec/index-management/dropSearchIndexes.yml index 435fd152bd0..2a29e3d4b99 100644 --- a/test/spec/index-management/dropSearchIndexes.yml +++ b/test/spec/index-management/dropSearchIndexes.yml @@ -16,16 +16,10 @@ createEntities: collectionName: *collection0 runOnRequirements: - - minServerVersion: "4.0.0" + - minServerVersion: "7.0.0" topologies: [ replicaset, load-balanced, sharded ] serverless: forbid -initialData: - # create the conection initially - - collectionName: *collection0 - databaseName: *database0 - documents: [] - tests: - description: "sends the correct command" operations: diff --git a/test/spec/index-management/listSearchIndexes.json b/test/spec/index-management/listSearchIndexes.json index 28b1c9d06ec..909eedbe81f 100644 --- a/test/spec/index-management/listSearchIndexes.json +++ b/test/spec/index-management/listSearchIndexes.json @@ -28,7 +28,7 @@ ], "runOnRequirements": [ { - "minServerVersion": "4.0.0", + "minServerVersion": "7.0.0", "topologies": [ "replicaset", "load-balanced", @@ -37,13 +37,6 @@ "serverless": "forbid" } ], - "initialData": [ - { - "collectionName": "collection0", - "databaseName": "database0", - "documents": [] - } - ], "tests": [ { "description": "when no name is provided, it does not populate the filter", @@ -113,6 +106,50 @@ ] } ] + }, + { + "description": "aggregation cursor options are supported", + "operations": [ + { + "name": "listSearchIndexes", + "object": "collection0", + "arguments": { + "indexName": "test index", + "options": { + "batchSize": 10 + } + }, + "saveResultAsEntity": "changeStream0", + "expectError": {} + } + ], + "expectEvents": [ + { + "client": "client0", + "ignoreExtraEvents": true, + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "collection0", + "cursor": { + "batchSize": 10 + }, + "pipeline": [ + { + "$$matchAsRoot": { + "$listSearchIndexes": { + "name": "test index" + } + } + } + ] + } + } + } + ] + } + ] } ] } diff --git a/test/spec/index-management/listSearchIndexes.yml b/test/spec/index-management/listSearchIndexes.yml index 3f012ac2c0b..c7c9ca7e62a 100644 --- a/test/spec/index-management/listSearchIndexes.yml +++ b/test/spec/index-management/listSearchIndexes.yml @@ -16,16 +16,10 @@ createEntities: collectionName: *collection0 runOnRequirements: - - minServerVersion: "4.0.0" + - minServerVersion: "7.0.0" topologies: [ replicaset, load-balanced, sharded ] serverless: forbid -initialData: - # create the conection initially - - collectionName: *collection0 - databaseName: *database0 - documents: [] - tests: - description: "when no name is provided, it does not populate the filter" operations: @@ -58,6 +52,29 @@ tests: - commandStartedEvent: command: aggregate: *collection0 + pipeline: + - $$matchAsRoot: + $listSearchIndexes: + { name: *indexName } + + - description: aggregation cursor options are supported + operations: + - name: listSearchIndexes + object: *collection0 + arguments: + indexName: &indexName "test index" + options: + batchSize: 10 + saveResultAsEntity: &changeStream0 changeStream0 + expectError: {} + expectEvents: + - client: *client0 + ignoreExtraEvents: true + events: + - commandStartedEvent: + command: + aggregate: *collection0 + cursor: { batchSize: 10 } pipeline: - $$matchAsRoot: $listSearchIndexes: diff --git a/test/spec/index-management/updateSearchIndex.json b/test/spec/index-management/updateSearchIndex.json index ac26b9d7fe2..0d24b601f8d 100644 --- a/test/spec/index-management/updateSearchIndex.json +++ b/test/spec/index-management/updateSearchIndex.json @@ -28,7 +28,7 @@ ], "runOnRequirements": [ { - "minServerVersion": "4.0.0", + "minServerVersion": "7.0.0", "topologies": [ "replicaset", "load-balanced", @@ -37,13 +37,6 @@ "serverless": "forbid" } ], - "initialData": [ - { - "collectionName": "collection0", - "databaseName": "database0", - "documents": [] - } - ], "tests": [ { "description": "sends the correct command", diff --git a/test/spec/index-management/updateSearchIndex.yml b/test/spec/index-management/updateSearchIndex.yml index 750de26bb24..e66f6c4cbf5 100644 --- a/test/spec/index-management/updateSearchIndex.yml +++ b/test/spec/index-management/updateSearchIndex.yml @@ -16,16 +16,10 @@ createEntities: collectionName: *collection0 runOnRequirements: - - minServerVersion: "4.0.0" + - minServerVersion: "7.0.0" topologies: [ replicaset, load-balanced, sharded ] serverless: forbid -initialData: - # create the conection initially - - collectionName: *collection0 - databaseName: *database0 - documents: [] - tests: - description: "sends the correct command" operations: diff --git a/test/tools/unified-spec-runner/operations.ts b/test/tools/unified-spec-runner/operations.ts index ef418629988..d1caaa28104 100644 --- a/test/tools/unified-spec-runner/operations.ts +++ b/test/tools/unified-spec-runner/operations.ts @@ -35,7 +35,7 @@ interface OperationFunctionParams { type RunOperationFn = ( p: OperationFunctionParams -) => Promise; +) => Promise; export const operations = new Map(); operations.set('createEntities', async ({ entities, operation, testConfig }) => { @@ -755,8 +755,8 @@ operations.set('getKeyByAltName', async ({ entities, operation }) => { operations.set('listSearchIndexes', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { indexName } = operation.arguments!; - return collection.listSearchIndexes(indexName).toArray(); + const { indexName, options } = operation.arguments!; + return collection.listSearchIndexes(indexName, options).toArray(); }); operations.set('dropSearchIndex', async ({ entities, operation }) => { @@ -771,6 +771,12 @@ operations.set('updateSearchIndex', async ({ entities, operation }) => { return collection.updateSearchIndex(indexName, definition); }); +operations.set('createSearchIndex', async ({ entities, operation }) => { + const collection: Collection = entities.getEntity('collection', operation.object); + const { definition } = operation.arguments!; + return collection.createSearchIndex(definition); +}); + operations.set('createSearchIndexes', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); const { indexDefinitions } = operation.arguments!; From 3ab6bc3a0e5a0747368dd1f9a9666b40ec473bf8 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 17 May 2023 14:48:01 -0600 Subject: [PATCH 08/24] misc cleanups --- src/collection.ts | 70 ++++++++++++++++++++++------------------------- src/db.ts | 33 ++++++++++------------ src/utils.ts | 2 +- 3 files changed, 48 insertions(+), 57 deletions(-) diff --git a/src/collection.ts b/src/collection.ts index bdcfbf72d17..b0218c41261 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -278,7 +278,7 @@ export class Collection { options?: InsertOneOptions ): Promise> { return executeOperation( - this.s.db.s.client, + this.client, new InsertOneOperation( this as TODO_NODE_3286, doc, @@ -300,7 +300,7 @@ export class Collection { options?: BulkWriteOptions ): Promise> { return executeOperation( - this.s.db.s.client, + this.client, new InsertManyOperation( this as TODO_NODE_3286, docs, @@ -337,7 +337,7 @@ export class Collection { } return executeOperation( - this.s.db.s.client, + this.client, new BulkWriteOperation( this as TODO_NODE_3286, operations as TODO_NODE_3286, @@ -359,7 +359,7 @@ export class Collection { options?: UpdateOptions ): Promise> { return executeOperation( - this.s.db.s.client, + this.client, new UpdateOneOperation( this as TODO_NODE_3286, filter, @@ -382,7 +382,7 @@ export class Collection { options?: ReplaceOptions ): Promise | Document> { return executeOperation( - this.s.db.s.client, + this.client, new ReplaceOneOperation( this as TODO_NODE_3286, filter, @@ -405,7 +405,7 @@ export class Collection { options?: UpdateOptions ): Promise> { return executeOperation( - this.s.db.s.client, + this.client, new UpdateManyOperation( this as TODO_NODE_3286, filter, @@ -426,7 +426,7 @@ export class Collection { options: DeleteOptions = {} ): Promise { return executeOperation( - this.s.db.s.client, + this.client, new DeleteOneOperation(this as TODO_NODE_3286, filter, resolveOptions(this, options)) ); } @@ -442,7 +442,7 @@ export class Collection { options: DeleteOptions = {} ): Promise { return executeOperation( - this.s.db.s.client, + this.client, new DeleteManyOperation(this as TODO_NODE_3286, filter, resolveOptions(this, options)) ); } @@ -459,7 +459,7 @@ export class Collection { async rename(newName: string, options?: RenameOptions): Promise { // Intentionally, we do not inherit options from parent for this operation. return executeOperation( - this.s.db.s.client, + this.client, new RenameOperation(this as TODO_NODE_3286, newName, { ...options, readPreference: ReadPreference.PRIMARY @@ -474,7 +474,7 @@ export class Collection { */ async drop(options?: DropCollectionOptions): Promise { return executeOperation( - this.s.db.s.client, + this.client, new DropCollectionOperation(this.s.db, this.collectionName, options) ); } @@ -511,7 +511,7 @@ export class Collection { find(filter: Filter, options?: FindOptions): FindCursor; find(filter: Filter = {}, options: FindOptions = {}): FindCursor> { return new FindCursor>( - this.s.db.s.client, + this.client, this.s.namespace, filter, resolveOptions(this as TODO_NODE_3286, options) @@ -525,7 +525,7 @@ export class Collection { */ async options(options?: OperationOptions): Promise { return executeOperation( - this.s.db.s.client, + this.client, new OptionsOperation(this as TODO_NODE_3286, resolveOptions(this, options)) ); } @@ -537,7 +537,7 @@ export class Collection { */ async isCapped(options?: OperationOptions): Promise { return executeOperation( - this.s.db.s.client, + this.client, new IsCappedOperation(this as TODO_NODE_3286, resolveOptions(this, options)) ); } @@ -575,7 +575,7 @@ export class Collection { options?: CreateIndexesOptions ): Promise { return executeOperation( - this.s.db.s.client, + this.client, new CreateIndexOperation( this as TODO_NODE_3286, this.collectionName, @@ -621,7 +621,7 @@ export class Collection { options?: CreateIndexesOptions ): Promise { return executeOperation( - this.s.db.s.client, + this.client, new CreateIndexesOperation( this as TODO_NODE_3286, this.collectionName, @@ -639,7 +639,7 @@ export class Collection { */ async dropIndex(indexName: string, options?: DropIndexesOptions): Promise { return executeOperation( - this.s.db.s.client, + this.client, new DropIndexOperation(this as TODO_NODE_3286, indexName, { ...resolveOptions(this, options), readPreference: ReadPreference.primary @@ -654,7 +654,7 @@ export class Collection { */ async dropIndexes(options?: DropIndexesOptions): Promise { return executeOperation( - this.s.db.s.client, + this.client, new DropIndexesOperation(this as TODO_NODE_3286, resolveOptions(this, options)) ); } @@ -679,7 +679,7 @@ export class Collection { options?: IndexInformationOptions ): Promise { return executeOperation( - this.s.db.s.client, + this.client, new IndexExistsOperation(this as TODO_NODE_3286, indexes, resolveOptions(this, options)) ); } @@ -691,7 +691,7 @@ export class Collection { */ async indexInformation(options?: IndexInformationOptions): Promise { return executeOperation( - this.s.db.s.client, + this.client, new IndexInformationOperation(this.s.db, this.collectionName, resolveOptions(this, options)) ); } @@ -711,7 +711,7 @@ export class Collection { */ async estimatedDocumentCount(options?: EstimatedDocumentCountOptions): Promise { return executeOperation( - this.s.db.s.client, + this.client, new EstimatedDocumentCountOperation(this as TODO_NODE_3286, resolveOptions(this, options)) ); } @@ -746,7 +746,7 @@ export class Collection { options: CountDocumentsOptions = {} ): Promise { return executeOperation( - this.s.db.s.client, + this.client, new CountDocumentsOperation(this as TODO_NODE_3286, filter, resolveOptions(this, options)) ); } @@ -782,7 +782,7 @@ export class Collection { options: DistinctOptions = {} ): Promise { return executeOperation( - this.s.db.s.client, + this.client, new DistinctOperation( this as TODO_NODE_3286, key as TODO_NODE_3286, @@ -799,7 +799,7 @@ export class Collection { */ async indexes(options?: IndexInformationOptions): Promise { return executeOperation( - this.s.db.s.client, + this.client, new IndexesOperation(this as TODO_NODE_3286, resolveOptions(this, options)) ); } @@ -814,7 +814,7 @@ export class Collection { */ async stats(options?: CollStatsOptions): Promise { return executeOperation( - this.s.db.s.client, + this.client, new CollStatsOperation(this as TODO_NODE_3286, options) as TODO_NODE_3286 ); } @@ -830,7 +830,7 @@ export class Collection { options?: FindOneAndDeleteOptions ): Promise> { return executeOperation( - this.s.db.s.client, + this.client, new FindOneAndDeleteOperation( this as TODO_NODE_3286, filter, @@ -852,7 +852,7 @@ export class Collection { options?: FindOneAndReplaceOptions ): Promise> { return executeOperation( - this.s.db.s.client, + this.client, new FindOneAndReplaceOperation( this as TODO_NODE_3286, filter, @@ -875,7 +875,7 @@ export class Collection { options?: FindOneAndUpdateOptions ): Promise> { return executeOperation( - this.s.db.s.client, + this.client, new FindOneAndUpdateOperation( this as TODO_NODE_3286, filter, @@ -902,7 +902,7 @@ export class Collection { } return new AggregationCursor( - this.s.db.s.client, + this.client, this.s.namespace, pipeline, resolveOptions(this, options) @@ -998,7 +998,7 @@ export class Collection { */ async count(filter: Filter = {}, options: CountOptions = {}): Promise { return executeOperation( - this.s.db.s.client, + this.client, new CountOperation(this.fullNamespace, filter, resolveOptions(this, options)) ); } @@ -1029,20 +1029,14 @@ export class Collection { async createSearchIndexes( descriptions: ReadonlyArray ): Promise { - return executeOperation( - this.s.db.s.client, - new CreateSearchIndexesOperation(this, descriptions) - ); + return executeOperation(this.client, new CreateSearchIndexesOperation(this, descriptions)); } async dropSearchIndex(name: string): Promise { - return executeOperation(this.s.db.s.client, new DropSearchIndexOperation(this, name)); + return executeOperation(this.client, new DropSearchIndexOperation(this, name)); } async updateSearchIndex(name: string, definition: Document): Promise { - return executeOperation( - this.s.db.s.client, - new UpdateSearchIndexOperation(this, name, definition) - ); + return executeOperation(this.client, new UpdateSearchIndexOperation(this, name, definition)); } } diff --git a/src/db.ts b/src/db.ts index e70057c45e9..db6f45ccfe8 100644 --- a/src/db.ts +++ b/src/db.ts @@ -196,7 +196,7 @@ export class Db { */ get readPreference(): ReadPreference { if (this.s.readPreference == null) { - return this.s.client.readPreference; + return this.client.readPreference; } return this.s.readPreference; @@ -227,7 +227,7 @@ export class Db { options?: CreateCollectionOptions ): Promise> { return executeOperation( - this.s.client, + this.client, new CreateCollectionOperation(this, name, resolveOptions(this, options)) as TODO_NODE_3286 ); } @@ -259,7 +259,7 @@ export class Db { */ async command(command: Document, options?: RunCommandOptions): Promise { // Intentionally, we do not inherit options from parent for this operation. - return executeOperation(this.s.client, new RunCommandOperation(this, command, options)); + return executeOperation(this.client, new RunCommandOperation(this, command, options)); } /** @@ -273,7 +273,7 @@ export class Db { options?: AggregateOptions ): AggregationCursor { return new AggregationCursor( - this.s.client, + this.client, this.s.namespace, pipeline, resolveOptions(this, options) @@ -307,10 +307,7 @@ export class Db { * @param options - Optional settings for the command */ async stats(options?: DbStatsOptions): Promise { - return executeOperation( - this.s.client, - new DbStatsOperation(this, resolveOptions(this, options)) - ); + return executeOperation(this.client, new DbStatsOperation(this, resolveOptions(this, options))); } /** @@ -357,7 +354,7 @@ export class Db { ): Promise> { // Intentionally, we do not inherit options from parent for this operation. return executeOperation( - this.s.client, + this.client, new RenameOperation( this.collection(fromCollection) as TODO_NODE_3286, toCollection, @@ -374,7 +371,7 @@ export class Db { */ async dropCollection(name: string, options?: DropCollectionOptions): Promise { return executeOperation( - this.s.client, + this.client, new DropCollectionOperation(this, name, resolveOptions(this, options)) ); } @@ -386,7 +383,7 @@ export class Db { */ async dropDatabase(options?: DropDatabaseOptions): Promise { return executeOperation( - this.s.client, + this.client, new DropDatabaseOperation(this, resolveOptions(this, options)) ); } @@ -398,7 +395,7 @@ export class Db { */ async collections(options?: ListCollectionsOptions): Promise { return executeOperation( - this.s.client, + this.client, new CollectionsOperation(this, resolveOptions(this, options)) ); } @@ -416,7 +413,7 @@ export class Db { options?: CreateIndexesOptions ): Promise { return executeOperation( - this.s.client, + this.client, new CreateIndexOperation(this, name, indexSpec, resolveOptions(this, options)) ); } @@ -443,7 +440,7 @@ export class Db { : undefined; const password = typeof passwordOrOptions === 'string' ? passwordOrOptions : undefined; return executeOperation( - this.s.client, + this.client, new AddUserOperation(this, username, password, resolveOptions(this, options)) ); } @@ -456,7 +453,7 @@ export class Db { */ async removeUser(username: string, options?: RemoveUserOptions): Promise { return executeOperation( - this.s.client, + this.client, new RemoveUserOperation(this, username, resolveOptions(this, options)) ); } @@ -472,7 +469,7 @@ export class Db { options?: SetProfilingLevelOptions ): Promise { return executeOperation( - this.s.client, + this.client, new SetProfilingLevelOperation(this, level, resolveOptions(this, options)) ); } @@ -484,7 +481,7 @@ export class Db { */ async profilingLevel(options?: ProfilingLevelOptions): Promise { return executeOperation( - this.s.client, + this.client, new ProfilingLevelOperation(this, resolveOptions(this, options)) ); } @@ -497,7 +494,7 @@ export class Db { */ async indexInformation(name: string, options?: IndexInformationOptions): Promise { return executeOperation( - this.s.client, + this.client, new IndexInformationOperation(this, name, resolveOptions(this, options)) ); } diff --git a/src/utils.ts b/src/utils.ts index d61f4c0f426..e929cd3b1aa 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -337,7 +337,7 @@ export class MongoDBNamespace { /** * @public * - * A class representing a collection's namespace. This class enforces that + * A class representing a collection's namespace. This class enforces (through Typescript) that * the `collection` portion of the namespace is defined and should only be * used in scenarios where this can be guaranteed. */ From a152b27b772a5e8c57ad627c79ba53930ed61b45 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 17 May 2023 14:52:14 -0600 Subject: [PATCH 09/24] sync tests --- test/spec/index-management/createSearchIndex.json | 8 ++++++-- test/spec/index-management/createSearchIndex.yml | 6 ++++-- test/spec/index-management/createSearchIndexes.json | 12 +++++++++--- test/spec/index-management/createSearchIndexes.yml | 9 ++++++--- test/spec/index-management/dropSearchIndexes.json | 4 +++- test/spec/index-management/dropSearchIndexes.yml | 3 ++- test/spec/index-management/listSearchIndexes.json | 12 +++++++++--- test/spec/index-management/listSearchIndexes.yml | 9 ++++++--- test/spec/index-management/updateSearchIndex.json | 4 +++- test/spec/index-management/updateSearchIndex.yml | 3 ++- 10 files changed, 50 insertions(+), 20 deletions(-) diff --git a/test/spec/index-management/createSearchIndex.json b/test/spec/index-management/createSearchIndex.json index 56b65939820..d29b6f8502f 100644 --- a/test/spec/index-management/createSearchIndex.json +++ b/test/spec/index-management/createSearchIndex.json @@ -49,7 +49,9 @@ "definition": {} } }, - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ @@ -85,7 +87,9 @@ "name": "test index" } }, - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ diff --git a/test/spec/index-management/createSearchIndex.yml b/test/spec/index-management/createSearchIndex.yml index b9fa6cbf900..522064330ea 100644 --- a/test/spec/index-management/createSearchIndex.yml +++ b/test/spec/index-management/createSearchIndex.yml @@ -27,7 +27,8 @@ tests: object: *collection0 arguments: definition: { definition: {} } - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true @@ -43,7 +44,8 @@ tests: object: *collection0 arguments: definition: { definition: {}, name: 'test index' } - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true diff --git a/test/spec/index-management/createSearchIndexes.json b/test/spec/index-management/createSearchIndexes.json index a47b68e3cb5..0c574ea8b43 100644 --- a/test/spec/index-management/createSearchIndexes.json +++ b/test/spec/index-management/createSearchIndexes.json @@ -47,7 +47,9 @@ "arguments": { "indexDefinitions": [] }, - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ @@ -80,7 +82,9 @@ } ] }, - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ @@ -118,7 +122,9 @@ } ] }, - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ diff --git a/test/spec/index-management/createSearchIndexes.yml b/test/spec/index-management/createSearchIndexes.yml index 2482fa0723f..9ccc0b36afe 100644 --- a/test/spec/index-management/createSearchIndexes.yml +++ b/test/spec/index-management/createSearchIndexes.yml @@ -27,7 +27,8 @@ tests: object: *collection0 arguments: indexDefinitions: [] - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true @@ -43,7 +44,8 @@ tests: object: *collection0 arguments: indexDefinitions: [ { definition: {} } ] - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true @@ -59,7 +61,8 @@ tests: object: *collection0 arguments: indexDefinitions: [ { definition: {}, name: 'test index' } ] - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true diff --git a/test/spec/index-management/dropSearchIndexes.json b/test/spec/index-management/dropSearchIndexes.json index 87854300a70..003feffffb9 100644 --- a/test/spec/index-management/dropSearchIndexes.json +++ b/test/spec/index-management/dropSearchIndexes.json @@ -47,7 +47,9 @@ "arguments": { "indexName": "test index" }, - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ diff --git a/test/spec/index-management/dropSearchIndexes.yml b/test/spec/index-management/dropSearchIndexes.yml index 2a29e3d4b99..0377bdbd5f4 100644 --- a/test/spec/index-management/dropSearchIndexes.yml +++ b/test/spec/index-management/dropSearchIndexes.yml @@ -27,7 +27,8 @@ tests: object: *collection0 arguments: indexName: &indexName 'test index' - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true diff --git a/test/spec/index-management/listSearchIndexes.json b/test/spec/index-management/listSearchIndexes.json index 909eedbe81f..fed84fd1698 100644 --- a/test/spec/index-management/listSearchIndexes.json +++ b/test/spec/index-management/listSearchIndexes.json @@ -45,7 +45,9 @@ "name": "listSearchIndexes", "object": "collection0", "arguments": [], - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ @@ -79,7 +81,9 @@ "indexName": "test index" }, "saveResultAsEntity": "changeStream0", - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ @@ -120,7 +124,9 @@ } }, "saveResultAsEntity": "changeStream0", - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ diff --git a/test/spec/index-management/listSearchIndexes.yml b/test/spec/index-management/listSearchIndexes.yml index c7c9ca7e62a..24847b1cb44 100644 --- a/test/spec/index-management/listSearchIndexes.yml +++ b/test/spec/index-management/listSearchIndexes.yml @@ -26,7 +26,8 @@ tests: - name: listSearchIndexes object: *collection0 arguments: [] - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true @@ -44,7 +45,8 @@ tests: arguments: indexName: &indexName "test index" saveResultAsEntity: &changeStream0 changeStream0 - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true @@ -66,7 +68,8 @@ tests: options: batchSize: 10 saveResultAsEntity: &changeStream0 changeStream0 - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true diff --git a/test/spec/index-management/updateSearchIndex.json b/test/spec/index-management/updateSearchIndex.json index 0d24b601f8d..73e9cccde3b 100644 --- a/test/spec/index-management/updateSearchIndex.json +++ b/test/spec/index-management/updateSearchIndex.json @@ -48,7 +48,9 @@ "indexName": "test index", "definition": {} }, - "expectError": {} + "expectError": { + "isError": true + } } ], "expectEvents": [ diff --git a/test/spec/index-management/updateSearchIndex.yml b/test/spec/index-management/updateSearchIndex.yml index e66f6c4cbf5..62508810a06 100644 --- a/test/spec/index-management/updateSearchIndex.yml +++ b/test/spec/index-management/updateSearchIndex.yml @@ -28,7 +28,8 @@ tests: arguments: indexName: &indexName 'test index' definition: &definition {} - expectError: {} + expectError: + isError: true expectEvents: - client: *client0 ignoreExtraEvents: true From 2b8410715bf8deb7f3f8200490baab27aef957f0 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 18 May 2023 10:32:01 -0600 Subject: [PATCH 10/24] sync tests --- .../index-management/createSearchIndex.json | 30 +++++++++++++---- .../index-management/createSearchIndex.yml | 11 ++++--- .../index-management/createSearchIndexes.json | 33 +++++++++++++++---- .../index-management/createSearchIndexes.yml | 14 +++++--- .../index-management/dropSearchIndexes.json | 3 +- .../index-management/dropSearchIndexes.yml | 2 ++ .../index-management/listSearchIndexes.json | 18 +++++----- .../index-management/listSearchIndexes.yml | 11 +++---- .../index-management/updateSearchIndex.json | 3 +- .../index-management/updateSearchIndex.yml | 2 ++ 10 files changed, 88 insertions(+), 39 deletions(-) diff --git a/test/spec/index-management/createSearchIndex.json b/test/spec/index-management/createSearchIndex.json index d29b6f8502f..9e98fe800dc 100644 --- a/test/spec/index-management/createSearchIndex.json +++ b/test/spec/index-management/createSearchIndex.json @@ -46,7 +46,11 @@ "object": "collection0", "arguments": { "definition": { - "definition": {} + "definition": { + "mappings": { + "dynamic": true + } + } } }, "expectError": { @@ -65,9 +69,14 @@ "createSearchIndexes": "collection0", "indexes": [ { - "definition": {} + "definition": { + "mappings": { + "dynamic": true + } + } } - ] + ], + "$db": "database0" } } } @@ -83,7 +92,11 @@ "object": "collection0", "arguments": { "definition": { - "definition": {}, + "definition": { + "mappings": { + "dynamic": true + } + }, "name": "test index" } }, @@ -103,10 +116,15 @@ "createSearchIndexes": "collection0", "indexes": [ { - "definition": {}, + "definition": { + "mappings": { + "dynamic": true + } + }, "name": "test index" } - ] + ], + "$db": "database0" } } } diff --git a/test/spec/index-management/createSearchIndex.yml b/test/spec/index-management/createSearchIndex.yml index 522064330ea..2545de56a19 100644 --- a/test/spec/index-management/createSearchIndex.yml +++ b/test/spec/index-management/createSearchIndex.yml @@ -26,7 +26,7 @@ tests: - name: createSearchIndex object: *collection0 arguments: - definition: { definition: {} } + definition: { definition: &definition { mappings: { dynamic: true } } } expectError: isError: true expectEvents: @@ -36,14 +36,15 @@ tests: - commandStartedEvent: command: createSearchIndexes: *collection0 - indexes: [ { definition: {} } ] + indexes: [ { definition: *definition } ] + $db: *database0 - description: "name provided for an index definition" operations: - name: createSearchIndex object: *collection0 arguments: - definition: { definition: {}, name: 'test index' } + definition: { definition: &definition { mappings: { dynamic: true } } , name: 'test index' } expectError: isError: true expectEvents: @@ -53,7 +54,9 @@ tests: - commandStartedEvent: command: createSearchIndexes: *collection0 - indexes: [ { definition: {}, name: 'test index' } ] + indexes: [ { definition: *definition, name: 'test index' } ] + $db: *database0 + \ No newline at end of file diff --git a/test/spec/index-management/createSearchIndexes.json b/test/spec/index-management/createSearchIndexes.json index 0c574ea8b43..7f219f8418a 100644 --- a/test/spec/index-management/createSearchIndexes.json +++ b/test/spec/index-management/createSearchIndexes.json @@ -61,7 +61,8 @@ "commandStartedEvent": { "command": { "createSearchIndexes": "collection0", - "indexes": [] + "indexes": [], + "$db": "database0" } } } @@ -78,7 +79,11 @@ "arguments": { "indexDefinitions": [ { - "definition": {} + "definition": { + "mappings": { + "dynamic": true + } + } } ] }, @@ -98,9 +103,14 @@ "createSearchIndexes": "collection0", "indexes": [ { - "definition": {} + "definition": { + "mappings": { + "dynamic": true + } + } } - ] + ], + "$db": "database0" } } } @@ -117,7 +127,11 @@ "arguments": { "indexDefinitions": [ { - "definition": {}, + "definition": { + "mappings": { + "dynamic": true + } + }, "name": "test index" } ] @@ -138,10 +152,15 @@ "createSearchIndexes": "collection0", "indexes": [ { - "definition": {}, + "definition": { + "mappings": { + "dynamic": true + } + }, "name": "test index" } - ] + ], + "$db": "database0" } } } diff --git a/test/spec/index-management/createSearchIndexes.yml b/test/spec/index-management/createSearchIndexes.yml index 9ccc0b36afe..d6f039907be 100644 --- a/test/spec/index-management/createSearchIndexes.yml +++ b/test/spec/index-management/createSearchIndexes.yml @@ -37,13 +37,15 @@ tests: command: createSearchIndexes: *collection0 indexes: [] + $db: *database0 + - description: "no name provided for an index definition" operations: - name: createSearchIndexes object: *collection0 arguments: - indexDefinitions: [ { definition: {} } ] + indexDefinitions: [ { definition: &definition { mappings: { dynamic: true } } } ] expectError: isError: true expectEvents: @@ -53,14 +55,16 @@ tests: - commandStartedEvent: command: createSearchIndexes: *collection0 - indexes: [ { definition: {} } ] + indexes: [ { definition: *definition } ] + $db: *database0 + - description: "name provided for an index definition" operations: - name: createSearchIndexes object: *collection0 arguments: - indexDefinitions: [ { definition: {}, name: 'test index' } ] + indexDefinitions: [ { definition: &definition { mappings: { dynamic: true } } , name: 'test index' } ] expectError: isError: true expectEvents: @@ -70,7 +74,9 @@ tests: - commandStartedEvent: command: createSearchIndexes: *collection0 - indexes: [ { definition: {}, name: 'test index' } ] + indexes: [ { definition: *definition, name: 'test index' } ] + $db: *database0 + \ No newline at end of file diff --git a/test/spec/index-management/dropSearchIndexes.json b/test/spec/index-management/dropSearchIndexes.json index 003feffffb9..338a19c7245 100644 --- a/test/spec/index-management/dropSearchIndexes.json +++ b/test/spec/index-management/dropSearchIndexes.json @@ -61,7 +61,8 @@ "commandStartedEvent": { "command": { "dropSearchIndex": "collection0", - "name": "test index" + "name": "test index", + "$db": "database0" } } } diff --git a/test/spec/index-management/dropSearchIndexes.yml b/test/spec/index-management/dropSearchIndexes.yml index 0377bdbd5f4..3736e6dfdc8 100644 --- a/test/spec/index-management/dropSearchIndexes.yml +++ b/test/spec/index-management/dropSearchIndexes.yml @@ -37,3 +37,5 @@ tests: command: dropSearchIndex: *collection0 name: *indexName + $db: *database0 + diff --git a/test/spec/index-management/listSearchIndexes.json b/test/spec/index-management/listSearchIndexes.json index fed84fd1698..74a0efd6315 100644 --- a/test/spec/index-management/listSearchIndexes.json +++ b/test/spec/index-management/listSearchIndexes.json @@ -97,13 +97,12 @@ "aggregate": "collection0", "pipeline": [ { - "$$matchAsRoot": { - "$listSearchIndexes": { - "name": "test index" - } + "$listSearchIndexes": { + "name": "test index" } } - ] + ], + "$db": "database0" } } } @@ -143,13 +142,12 @@ }, "pipeline": [ { - "$$matchAsRoot": { - "$listSearchIndexes": { - "name": "test index" - } + "$listSearchIndexes": { + "name": "test index" } } - ] + ], + "$db": "database0" } } } diff --git a/test/spec/index-management/listSearchIndexes.yml b/test/spec/index-management/listSearchIndexes.yml index 24847b1cb44..d44962356c2 100644 --- a/test/spec/index-management/listSearchIndexes.yml +++ b/test/spec/index-management/listSearchIndexes.yml @@ -55,9 +55,8 @@ tests: command: aggregate: *collection0 pipeline: - - $$matchAsRoot: - $listSearchIndexes: - { name: *indexName } + - $listSearchIndexes: { name: *indexName } + $db: *database0 - description: aggregation cursor options are supported operations: @@ -79,6 +78,6 @@ tests: aggregate: *collection0 cursor: { batchSize: 10 } pipeline: - - $$matchAsRoot: - $listSearchIndexes: - { name: *indexName } \ No newline at end of file + - $listSearchIndexes: { name: *indexName } + $db: *database0 + diff --git a/test/spec/index-management/updateSearchIndex.json b/test/spec/index-management/updateSearchIndex.json index 73e9cccde3b..14e6f0c8f40 100644 --- a/test/spec/index-management/updateSearchIndex.json +++ b/test/spec/index-management/updateSearchIndex.json @@ -63,7 +63,8 @@ "command": { "updateSearchIndex": "collection0", "name": "test index", - "definition": {} + "definition": {}, + "$db": "database0" } } } diff --git a/test/spec/index-management/updateSearchIndex.yml b/test/spec/index-management/updateSearchIndex.yml index 62508810a06..425d11d38e9 100644 --- a/test/spec/index-management/updateSearchIndex.yml +++ b/test/spec/index-management/updateSearchIndex.yml @@ -39,3 +39,5 @@ tests: updateSearchIndex: *collection0 name: *indexName definition: *definition + $db: *database0 + From 8fe15a5c6d4c1afaa3cda1d6209713c9592f775b Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 18 May 2023 10:40:35 -0600 Subject: [PATCH 11/24] fix failing schema tsets --- test/spec/index-management/listSearchIndexes.json | 2 +- test/spec/index-management/listSearchIndexes.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/index-management/listSearchIndexes.json b/test/spec/index-management/listSearchIndexes.json index 74a0efd6315..f1b202598bc 100644 --- a/test/spec/index-management/listSearchIndexes.json +++ b/test/spec/index-management/listSearchIndexes.json @@ -44,7 +44,7 @@ { "name": "listSearchIndexes", "object": "collection0", - "arguments": [], + "arguments": {}, "expectError": { "isError": true } diff --git a/test/spec/index-management/listSearchIndexes.yml b/test/spec/index-management/listSearchIndexes.yml index d44962356c2..2ae577b5f78 100644 --- a/test/spec/index-management/listSearchIndexes.yml +++ b/test/spec/index-management/listSearchIndexes.yml @@ -25,7 +25,7 @@ tests: operations: - name: listSearchIndexes object: *collection0 - arguments: [] + arguments: {} expectError: isError: true expectEvents: From 9949463e201d6df01270800fcfa3a0dc646414fb Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 18 May 2023 11:33:05 -0600 Subject: [PATCH 12/24] fix schema tests && update UTR operations --- test/spec/index-management/listSearchIndexes.json | 3 --- test/spec/index-management/listSearchIndexes.yml | 3 --- test/tools/unified-spec-runner/operations.ts | 12 ++++++------ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/spec/index-management/listSearchIndexes.json b/test/spec/index-management/listSearchIndexes.json index f1b202598bc..97259ee359c 100644 --- a/test/spec/index-management/listSearchIndexes.json +++ b/test/spec/index-management/listSearchIndexes.json @@ -44,7 +44,6 @@ { "name": "listSearchIndexes", "object": "collection0", - "arguments": {}, "expectError": { "isError": true } @@ -80,7 +79,6 @@ "arguments": { "indexName": "test index" }, - "saveResultAsEntity": "changeStream0", "expectError": { "isError": true } @@ -122,7 +120,6 @@ "batchSize": 10 } }, - "saveResultAsEntity": "changeStream0", "expectError": { "isError": true } diff --git a/test/spec/index-management/listSearchIndexes.yml b/test/spec/index-management/listSearchIndexes.yml index 2ae577b5f78..5a2bf7fcb07 100644 --- a/test/spec/index-management/listSearchIndexes.yml +++ b/test/spec/index-management/listSearchIndexes.yml @@ -25,7 +25,6 @@ tests: operations: - name: listSearchIndexes object: *collection0 - arguments: {} expectError: isError: true expectEvents: @@ -44,7 +43,6 @@ tests: object: *collection0 arguments: indexName: &indexName "test index" - saveResultAsEntity: &changeStream0 changeStream0 expectError: isError: true expectEvents: @@ -66,7 +64,6 @@ tests: indexName: &indexName "test index" options: batchSize: 10 - saveResultAsEntity: &changeStream0 changeStream0 expectError: isError: true expectEvents: diff --git a/test/tools/unified-spec-runner/operations.ts b/test/tools/unified-spec-runner/operations.ts index d1caaa28104..562b065cbc1 100644 --- a/test/tools/unified-spec-runner/operations.ts +++ b/test/tools/unified-spec-runner/operations.ts @@ -748,38 +748,38 @@ operations.set('removeKeyAltName', async ({ entities, operation }) => { operations.set('getKeyByAltName', async ({ entities, operation }) => { const clientEncryption = entities.getEntity('clientEncryption', operation.object); - const { keyAltName } = operation.arguments!; + const { keyAltName } = operation.arguments ?? {}; return clientEncryption.getKeyByAltName(keyAltName); }); operations.set('listSearchIndexes', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { indexName, options } = operation.arguments!; + const { indexName, options } = operation.arguments ?? {}; return collection.listSearchIndexes(indexName, options).toArray(); }); operations.set('dropSearchIndex', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { indexName } = operation.arguments!; + const { indexName } = operation.arguments ?? {}; return collection.dropSearchIndex(indexName); }); operations.set('updateSearchIndex', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { indexName, definition } = operation.arguments!; + const { indexName, definition } = operation.arguments ?? {}; return collection.updateSearchIndex(indexName, definition); }); operations.set('createSearchIndex', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { definition } = operation.arguments!; + const { definition } = operation.arguments ?? {}; return collection.createSearchIndex(definition); }); operations.set('createSearchIndexes', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { indexDefinitions } = operation.arguments!; + const { indexDefinitions } = operation.arguments ?? {}; return collection.createSearchIndexes(indexDefinitions); }); From 0c1cacf2677637ac3148c3e440a772b0a585dd98 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Mon, 22 May 2023 09:03:23 -0600 Subject: [PATCH 13/24] move search index tests to manual test directory --- package.json | 4 ++-- .../index-management/index-management.spec.test.ts | 8 -------- test/manual/search-index-management.spec.test.ts | 8 ++++++++ 3 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 test/integration/index-management/index-management.spec.test.ts create mode 100644 test/manual/search-index-management.spec.test.ts diff --git a/package.json b/package.json index 1faf5ef3dbb..b8b9c087ee9 100644 --- a/package.json +++ b/package.json @@ -120,8 +120,8 @@ "check:tsd": "tsd --version && tsd", "check:dependencies": "mocha test/action/dependency.test.ts", "check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd", - "check:search-indexes": "mocha --config test/mocha_mongodb.json test/integration/index-management", - "check:test": "mocha --config test/mocha_mongodb.json --exclude test/integration/index-management/**ts test/integration", + "check:search-indexes": "mocha --config test/mocha_mongodb.json test/manual/search-index-management.spec.test.ts", + "check:test": "mocha --config test/mocha_mongodb.json test/integration", "check:unit": "mocha test/unit", "check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit", "check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js", diff --git a/test/integration/index-management/index-management.spec.test.ts b/test/integration/index-management/index-management.spec.test.ts deleted file mode 100644 index 3f1c9ae57a9..00000000000 --- a/test/integration/index-management/index-management.spec.test.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { join } from 'path'; - -import { loadSpecTests } from '../../spec'; -import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; - -describe('Index Management Tests (Unified)', function () { - runUnifiedSuite(loadSpecTests(join('index-management'))); -}); diff --git a/test/manual/search-index-management.spec.test.ts b/test/manual/search-index-management.spec.test.ts new file mode 100644 index 00000000000..ce7b7958fe6 --- /dev/null +++ b/test/manual/search-index-management.spec.test.ts @@ -0,0 +1,8 @@ +import { join } from 'path'; + +import { loadSpecTests } from '../spec'; +import { runUnifiedSuite } from '../tools/unified-spec-runner/runner'; + +describe('Search Index Management Tests (Unified)', function () { + runUnifiedSuite(loadSpecTests(join('index-management'))); +}); From cc4c43ad225649ca5dd794b6fc2153baf1875322 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 24 May 2023 07:57:37 -0600 Subject: [PATCH 14/24] sync changes to tests from review --- .../index-management/createSearchIndex.json | 8 +++---- .../index-management/createSearchIndex.yml | 18 +++++++-------- .../index-management/createSearchIndexes.json | 9 +++----- .../index-management/createSearchIndexes.yml | 22 +++++++++---------- .../index-management/dropSearchIndexes.json | 5 ++--- .../index-management/dropSearchIndexes.yml | 7 +++--- .../index-management/listSearchIndexes.json | 7 ++---- .../index-management/listSearchIndexes.yml | 16 ++++++++------ .../index-management/updateSearchIndex.json | 3 +-- .../index-management/updateSearchIndex.yml | 7 +++--- test/tools/unified-spec-runner/operations.ts | 20 ++++++++--------- 11 files changed, 56 insertions(+), 66 deletions(-) diff --git a/test/spec/index-management/createSearchIndex.json b/test/spec/index-management/createSearchIndex.json index 9e98fe800dc..3958fa9075e 100644 --- a/test/spec/index-management/createSearchIndex.json +++ b/test/spec/index-management/createSearchIndex.json @@ -1,5 +1,5 @@ { - "description": "createSearchIndex convenience helper", + "description": "createSearchIndex", "schemaVersion": "1.10", "createEntities": [ { @@ -45,7 +45,7 @@ "name": "createSearchIndex", "object": "collection0", "arguments": { - "definition": { + "model": { "definition": { "mappings": { "dynamic": true @@ -61,7 +61,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { @@ -91,7 +90,7 @@ "name": "createSearchIndex", "object": "collection0", "arguments": { - "definition": { + "model": { "definition": { "mappings": { "dynamic": true @@ -108,7 +107,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { diff --git a/test/spec/index-management/createSearchIndex.yml b/test/spec/index-management/createSearchIndex.yml index 2545de56a19..8e7fd81ec06 100644 --- a/test/spec/index-management/createSearchIndex.yml +++ b/test/spec/index-management/createSearchIndex.yml @@ -1,4 +1,4 @@ -description: "createSearchIndex convenience helper" +description: "createSearchIndex" schemaVersion: "1.10" createEntities: - client: @@ -26,12 +26,13 @@ tests: - name: createSearchIndex object: *collection0 arguments: - definition: { definition: &definition { mappings: { dynamic: true } } } + model: { definition: &definition { mappings: { dynamic: true } } } expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: @@ -44,19 +45,16 @@ tests: - name: createSearchIndex object: *collection0 arguments: - definition: { definition: &definition { mappings: { dynamic: true } } , name: 'test index' } + model: { definition: &definition { mappings: { dynamic: true } } , name: 'test index' } expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: createSearchIndexes: *collection0 indexes: [ { definition: *definition, name: 'test index' } ] - $db: *database0 - - - - \ No newline at end of file + $db: *database0 \ No newline at end of file diff --git a/test/spec/index-management/createSearchIndexes.json b/test/spec/index-management/createSearchIndexes.json index 7f219f8418a..dee1945f3b9 100644 --- a/test/spec/index-management/createSearchIndexes.json +++ b/test/spec/index-management/createSearchIndexes.json @@ -45,7 +45,7 @@ "name": "createSearchIndexes", "object": "collection0", "arguments": { - "indexDefinitions": [] + "models": [] }, "expectError": { "isError": true @@ -55,7 +55,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { @@ -77,7 +76,7 @@ "name": "createSearchIndexes", "object": "collection0", "arguments": { - "indexDefinitions": [ + "models": [ { "definition": { "mappings": { @@ -95,7 +94,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { @@ -125,7 +123,7 @@ "name": "createSearchIndexes", "object": "collection0", "arguments": { - "indexDefinitions": [ + "models": [ { "definition": { "mappings": { @@ -144,7 +142,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { diff --git a/test/spec/index-management/createSearchIndexes.yml b/test/spec/index-management/createSearchIndexes.yml index d6f039907be..2d4e459eeab 100644 --- a/test/spec/index-management/createSearchIndexes.yml +++ b/test/spec/index-management/createSearchIndexes.yml @@ -26,12 +26,13 @@ tests: - name: createSearchIndexes object: *collection0 arguments: - indexDefinitions: [] + models: [] expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: @@ -45,12 +46,13 @@ tests: - name: createSearchIndexes object: *collection0 arguments: - indexDefinitions: [ { definition: &definition { mappings: { dynamic: true } } } ] + models: [ { definition: &definition { mappings: { dynamic: true } } } ] expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: @@ -58,25 +60,21 @@ tests: indexes: [ { definition: *definition } ] $db: *database0 - - description: "name provided for an index definition" operations: - name: createSearchIndexes object: *collection0 arguments: - indexDefinitions: [ { definition: &definition { mappings: { dynamic: true } } , name: 'test index' } ] + models: [ { definition: &definition { mappings: { dynamic: true } } , name: 'test index' } ] expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: createSearchIndexes: *collection0 indexes: [ { definition: *definition, name: 'test index' } ] - $db: *database0 - - - - \ No newline at end of file + $db: *database0 \ No newline at end of file diff --git a/test/spec/index-management/dropSearchIndexes.json b/test/spec/index-management/dropSearchIndexes.json index 338a19c7245..ddf629d3309 100644 --- a/test/spec/index-management/dropSearchIndexes.json +++ b/test/spec/index-management/dropSearchIndexes.json @@ -1,5 +1,5 @@ { - "description": "dropSearchIndexes", + "description": "dropSearchIndex", "schemaVersion": "1.10", "createEntities": [ { @@ -45,7 +45,7 @@ "name": "dropSearchIndex", "object": "collection0", "arguments": { - "indexName": "test index" + "name": "test index" }, "expectError": { "isError": true @@ -55,7 +55,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { diff --git a/test/spec/index-management/dropSearchIndexes.yml b/test/spec/index-management/dropSearchIndexes.yml index 3736e6dfdc8..40736b6d246 100644 --- a/test/spec/index-management/dropSearchIndexes.yml +++ b/test/spec/index-management/dropSearchIndexes.yml @@ -1,4 +1,4 @@ -description: "dropSearchIndexes" +description: "dropSearchIndex" schemaVersion: "1.10" createEntities: - client: @@ -26,12 +26,13 @@ tests: - name: dropSearchIndex object: *collection0 arguments: - indexName: &indexName 'test index' + name: &indexName 'test index' expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: diff --git a/test/spec/index-management/listSearchIndexes.json b/test/spec/index-management/listSearchIndexes.json index 97259ee359c..3db7a7a419d 100644 --- a/test/spec/index-management/listSearchIndexes.json +++ b/test/spec/index-management/listSearchIndexes.json @@ -52,7 +52,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { @@ -77,7 +76,7 @@ "name": "listSearchIndexes", "object": "collection0", "arguments": { - "indexName": "test index" + "name": "test index" }, "expectError": { "isError": true @@ -87,7 +86,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { @@ -115,7 +113,7 @@ "name": "listSearchIndexes", "object": "collection0", "arguments": { - "indexName": "test index", + "name": "test index", "options": { "batchSize": 10 } @@ -128,7 +126,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { diff --git a/test/spec/index-management/listSearchIndexes.yml b/test/spec/index-management/listSearchIndexes.yml index 5a2bf7fcb07..7d227980610 100644 --- a/test/spec/index-management/listSearchIndexes.yml +++ b/test/spec/index-management/listSearchIndexes.yml @@ -26,10 +26,11 @@ tests: - name: listSearchIndexes object: *collection0 expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: @@ -42,12 +43,13 @@ tests: - name: listSearchIndexes object: *collection0 arguments: - indexName: &indexName "test index" + name: &indexName "test index" expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: @@ -61,14 +63,15 @@ tests: - name: listSearchIndexes object: *collection0 arguments: - indexName: &indexName "test index" + name: &indexName "test index" options: batchSize: 10 expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: @@ -76,5 +79,4 @@ tests: cursor: { batchSize: 10 } pipeline: - $listSearchIndexes: { name: *indexName } - $db: *database0 - + $db: *database0 \ No newline at end of file diff --git a/test/spec/index-management/updateSearchIndex.json b/test/spec/index-management/updateSearchIndex.json index 14e6f0c8f40..3c88d28ab5f 100644 --- a/test/spec/index-management/updateSearchIndex.json +++ b/test/spec/index-management/updateSearchIndex.json @@ -45,7 +45,7 @@ "name": "updateSearchIndex", "object": "collection0", "arguments": { - "indexName": "test index", + "name": "test index", "definition": {} }, "expectError": { @@ -56,7 +56,6 @@ "expectEvents": [ { "client": "client0", - "ignoreExtraEvents": true, "events": [ { "commandStartedEvent": { diff --git a/test/spec/index-management/updateSearchIndex.yml b/test/spec/index-management/updateSearchIndex.yml index 425d11d38e9..66a05141758 100644 --- a/test/spec/index-management/updateSearchIndex.yml +++ b/test/spec/index-management/updateSearchIndex.yml @@ -26,13 +26,14 @@ tests: - name: updateSearchIndex object: *collection0 arguments: - indexName: &indexName 'test index' + name: &indexName 'test index' definition: &definition {} - expectError: + expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. isError: true expectEvents: - client: *client0 - ignoreExtraEvents: true events: - commandStartedEvent: command: diff --git a/test/tools/unified-spec-runner/operations.ts b/test/tools/unified-spec-runner/operations.ts index 562b065cbc1..f56f12268e7 100644 --- a/test/tools/unified-spec-runner/operations.ts +++ b/test/tools/unified-spec-runner/operations.ts @@ -755,32 +755,32 @@ operations.set('getKeyByAltName', async ({ entities, operation }) => { operations.set('listSearchIndexes', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { indexName, options } = operation.arguments ?? {}; - return collection.listSearchIndexes(indexName, options).toArray(); + const { name, options } = operation.arguments ?? {}; + return collection.listSearchIndexes(name, options).toArray(); }); operations.set('dropSearchIndex', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { indexName } = operation.arguments ?? {}; - return collection.dropSearchIndex(indexName); + const { name } = operation.arguments ?? {}; + return collection.dropSearchIndex(name); }); operations.set('updateSearchIndex', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { indexName, definition } = operation.arguments ?? {}; - return collection.updateSearchIndex(indexName, definition); + const { name, definition } = operation.arguments ?? {}; + return collection.updateSearchIndex(name, definition); }); operations.set('createSearchIndex', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { definition } = operation.arguments ?? {}; - return collection.createSearchIndex(definition); + const { model } = operation.arguments ?? {}; + return collection.createSearchIndex(model); }); operations.set('createSearchIndexes', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { indexDefinitions } = operation.arguments ?? {}; - return collection.createSearchIndexes(indexDefinitions); + const { models } = operation.arguments ?? {}; + return collection.createSearchIndexes(models); }); export async function executeOperationAndCheck( From 2f95503e533e61dc388a114f770941b0eb72967c Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 24 May 2023 08:32:17 -0600 Subject: [PATCH 15/24] lower schema versoin to 1.3 --- test/spec/index-management/createSearchIndex.json | 2 +- test/spec/index-management/createSearchIndex.yml | 2 +- test/spec/index-management/createSearchIndexes.json | 2 +- test/spec/index-management/createSearchIndexes.yml | 2 +- test/spec/index-management/dropSearchIndexes.json | 2 +- test/spec/index-management/dropSearchIndexes.yml | 2 +- test/spec/index-management/listSearchIndexes.json | 2 +- test/spec/index-management/listSearchIndexes.yml | 2 +- test/spec/index-management/updateSearchIndex.json | 2 +- test/spec/index-management/updateSearchIndex.yml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/spec/index-management/createSearchIndex.json b/test/spec/index-management/createSearchIndex.json index 3958fa9075e..da664631e7b 100644 --- a/test/spec/index-management/createSearchIndex.json +++ b/test/spec/index-management/createSearchIndex.json @@ -1,6 +1,6 @@ { "description": "createSearchIndex", - "schemaVersion": "1.10", + "schemaVersion": "1.4", "createEntities": [ { "client": { diff --git a/test/spec/index-management/createSearchIndex.yml b/test/spec/index-management/createSearchIndex.yml index 8e7fd81ec06..0eb5c1ab1d3 100644 --- a/test/spec/index-management/createSearchIndex.yml +++ b/test/spec/index-management/createSearchIndex.yml @@ -1,5 +1,5 @@ description: "createSearchIndex" -schemaVersion: "1.10" +schemaVersion: "1.4" createEntities: - client: id: &client0 client0 diff --git a/test/spec/index-management/createSearchIndexes.json b/test/spec/index-management/createSearchIndexes.json index dee1945f3b9..b78b3ea6c87 100644 --- a/test/spec/index-management/createSearchIndexes.json +++ b/test/spec/index-management/createSearchIndexes.json @@ -1,6 +1,6 @@ { "description": "createSearchIndexes", - "schemaVersion": "1.10", + "schemaVersion": "1.4", "createEntities": [ { "client": { diff --git a/test/spec/index-management/createSearchIndexes.yml b/test/spec/index-management/createSearchIndexes.yml index 2d4e459eeab..dc01c1b1668 100644 --- a/test/spec/index-management/createSearchIndexes.yml +++ b/test/spec/index-management/createSearchIndexes.yml @@ -1,5 +1,5 @@ description: "createSearchIndexes" -schemaVersion: "1.10" +schemaVersion: "1.4" createEntities: - client: id: &client0 client0 diff --git a/test/spec/index-management/dropSearchIndexes.json b/test/spec/index-management/dropSearchIndexes.json index ddf629d3309..b73447f602c 100644 --- a/test/spec/index-management/dropSearchIndexes.json +++ b/test/spec/index-management/dropSearchIndexes.json @@ -1,6 +1,6 @@ { "description": "dropSearchIndex", - "schemaVersion": "1.10", + "schemaVersion": "1.4", "createEntities": [ { "client": { diff --git a/test/spec/index-management/dropSearchIndexes.yml b/test/spec/index-management/dropSearchIndexes.yml index 40736b6d246..5ffef7d17e4 100644 --- a/test/spec/index-management/dropSearchIndexes.yml +++ b/test/spec/index-management/dropSearchIndexes.yml @@ -1,5 +1,5 @@ description: "dropSearchIndex" -schemaVersion: "1.10" +schemaVersion: "1.4" createEntities: - client: id: &client0 client0 diff --git a/test/spec/index-management/listSearchIndexes.json b/test/spec/index-management/listSearchIndexes.json index 3db7a7a419d..a42df18c371 100644 --- a/test/spec/index-management/listSearchIndexes.json +++ b/test/spec/index-management/listSearchIndexes.json @@ -1,6 +1,6 @@ { "description": "listSearchIndexes", - "schemaVersion": "1.10", + "schemaVersion": "1.4", "createEntities": [ { "client": { diff --git a/test/spec/index-management/listSearchIndexes.yml b/test/spec/index-management/listSearchIndexes.yml index 7d227980610..9f2d9392270 100644 --- a/test/spec/index-management/listSearchIndexes.yml +++ b/test/spec/index-management/listSearchIndexes.yml @@ -1,5 +1,5 @@ description: "listSearchIndexes" -schemaVersion: "1.10" +schemaVersion: "1.4" createEntities: - client: id: &client0 client0 diff --git a/test/spec/index-management/updateSearchIndex.json b/test/spec/index-management/updateSearchIndex.json index 3c88d28ab5f..00cd7e75417 100644 --- a/test/spec/index-management/updateSearchIndex.json +++ b/test/spec/index-management/updateSearchIndex.json @@ -1,6 +1,6 @@ { "description": "updateSearchIndex", - "schemaVersion": "1.10", + "schemaVersion": "1.4", "createEntities": [ { "client": { diff --git a/test/spec/index-management/updateSearchIndex.yml b/test/spec/index-management/updateSearchIndex.yml index 66a05141758..215dbc42f92 100644 --- a/test/spec/index-management/updateSearchIndex.yml +++ b/test/spec/index-management/updateSearchIndex.yml @@ -1,5 +1,5 @@ description: "updateSearchIndex" -schemaVersion: "1.10" +schemaVersion: "1.4" createEntities: - client: id: &client0 client0 From 21d8e5f9a40607164bb96efd1803db2d81014371 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 24 May 2023 08:36:02 -0600 Subject: [PATCH 16/24] rename options to AggregationOptions --- test/spec/index-management/listSearchIndexes.json | 2 +- test/spec/index-management/listSearchIndexes.yml | 2 +- test/tools/unified-spec-runner/operations.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/spec/index-management/listSearchIndexes.json b/test/spec/index-management/listSearchIndexes.json index a42df18c371..41e2655fb3a 100644 --- a/test/spec/index-management/listSearchIndexes.json +++ b/test/spec/index-management/listSearchIndexes.json @@ -114,7 +114,7 @@ "object": "collection0", "arguments": { "name": "test index", - "options": { + "aggregationOptions": { "batchSize": 10 } }, diff --git a/test/spec/index-management/listSearchIndexes.yml b/test/spec/index-management/listSearchIndexes.yml index 9f2d9392270..7d3c3187b91 100644 --- a/test/spec/index-management/listSearchIndexes.yml +++ b/test/spec/index-management/listSearchIndexes.yml @@ -64,7 +64,7 @@ tests: object: *collection0 arguments: name: &indexName "test index" - options: + aggregationOptions: batchSize: 10 expectError: # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing diff --git a/test/tools/unified-spec-runner/operations.ts b/test/tools/unified-spec-runner/operations.ts index f56f12268e7..d0da156efb8 100644 --- a/test/tools/unified-spec-runner/operations.ts +++ b/test/tools/unified-spec-runner/operations.ts @@ -755,8 +755,8 @@ operations.set('getKeyByAltName', async ({ entities, operation }) => { operations.set('listSearchIndexes', async ({ entities, operation }) => { const collection: Collection = entities.getEntity('collection', operation.object); - const { name, options } = operation.arguments ?? {}; - return collection.listSearchIndexes(name, options).toArray(); + const { name, aggregationOptions } = operation.arguments ?? {}; + return collection.listSearchIndexes(name, aggregationOptions).toArray(); }); operations.set('dropSearchIndex', async ({ entities, operation }) => { From 126dea3f47250ee77774caed6df868a864cac70f Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Fri, 26 May 2023 10:51:17 -0600 Subject: [PATCH 17/24] rename 2 test files --- .../index-management/dropSearchIndex.json | 73 +++++++++++++++++++ .../spec/index-management/dropSearchIndex.yml | 42 +++++++++++ 2 files changed, 115 insertions(+) create mode 100644 test/spec/index-management/dropSearchIndex.json create mode 100644 test/spec/index-management/dropSearchIndex.yml diff --git a/test/spec/index-management/dropSearchIndex.json b/test/spec/index-management/dropSearchIndex.json new file mode 100644 index 00000000000..b73447f602c --- /dev/null +++ b/test/spec/index-management/dropSearchIndex.json @@ -0,0 +1,73 @@ +{ + "description": "dropSearchIndex", + "schemaVersion": "1.4", + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "database0" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "collection0" + } + } + ], + "runOnRequirements": [ + { + "minServerVersion": "7.0.0", + "topologies": [ + "replicaset", + "load-balanced", + "sharded" + ], + "serverless": "forbid" + } + ], + "tests": [ + { + "description": "sends the correct command", + "operations": [ + { + "name": "dropSearchIndex", + "object": "collection0", + "arguments": { + "name": "test index" + }, + "expectError": { + "isError": true + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "dropSearchIndex": "collection0", + "name": "test index", + "$db": "database0" + } + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/index-management/dropSearchIndex.yml b/test/spec/index-management/dropSearchIndex.yml new file mode 100644 index 00000000000..5ffef7d17e4 --- /dev/null +++ b/test/spec/index-management/dropSearchIndex.yml @@ -0,0 +1,42 @@ +description: "dropSearchIndex" +schemaVersion: "1.4" +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + observeEvents: + - commandStartedEvent + - database: + id: &database0 database0 + client: *client0 + databaseName: *database0 + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: *collection0 + +runOnRequirements: + - minServerVersion: "7.0.0" + topologies: [ replicaset, load-balanced, sharded ] + serverless: forbid + +tests: + - description: "sends the correct command" + operations: + - name: dropSearchIndex + object: *collection0 + arguments: + name: &indexName 'test index' + expectError: + # Search indexes are only available on 7.0+ atlas clusters. DRIVERS-2630 will add e2e testing + # against an Atlas cluster and the expectError will be removed. + isError: true + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + dropSearchIndex: *collection0 + name: *indexName + $db: *database0 + From 764d6ae19536a403091a0fb325f089ef000f4d79 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 30 May 2023 10:16:19 -0600 Subject: [PATCH 18/24] add doc comments and the internal tag to new collection helpers --- src/collection.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/collection.ts b/src/collection.ts index b0218c41261..9f5f73950b9 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -1003,6 +1003,16 @@ export class Collection { ); } + /** + * @internal + * + * Returns all search indexes for the current collection. + * + * @param indexName - Optional. If specified, only indexes with matching index names will be returned. + * @param options - The options for the list indexes operation. + * + * @remarks Only available when used against a 7.0+ Atlas cluster. + */ listSearchIndexes(options?: ListSearchIndexesOptions): ListSearchIndexesCursor; listSearchIndexes(indexName: string, options?: ListSearchIndexesOptions): ListSearchIndexesCursor; listSearchIndexes( @@ -1021,21 +1031,61 @@ export class Collection { return ListSearchIndexesCursor.create(this, indexName, options); } + /** + * @internal + * + * Creates a single search index for the collection. + * + * @param description - The index description for the new search index. + * @returns A promise that resolves to the name of the new search index. + * + * @remarks Only available when used against a 7.0+ Atlas cluster. + */ async createSearchIndex(description: SearchIndexDescription): Promise { const indexes = await this.createSearchIndexes([description]); return indexes[0]; } + /** + * @internal + * + * Creates multiple search indexes for the current collection. + * + * @param descriptions - An array of `SearchIndexDescription`s for the new search indexes. + * @returns A promise that resolves to an array of the newly created search index names. + * + * @remarks Only available when used against a 7.0+ Atlas cluster. + * @returns + */ async createSearchIndexes( descriptions: ReadonlyArray ): Promise { return executeOperation(this.client, new CreateSearchIndexesOperation(this, descriptions)); } + /** + * @internal + * + * Deletes a search index by index name. + * + * @param name - The name of the search index to be deleted. + * + * @remarks Only available when used against a 7.0+ Atlas cluster. + */ async dropSearchIndex(name: string): Promise { return executeOperation(this.client, new DropSearchIndexOperation(this, name)); } + /** + * @internal + * + * Updates a search index by replacing the existing index definition with the provided definition. + * + * @param name - The name of the search index to update. + * @param definition - The new search index definition. + * + * @remarks Only available when used against a 7.0+ Atlas cluster. + */ async updateSearchIndex(name: string, definition: Document): Promise { return executeOperation(this.client, new UpdateSearchIndexOperation(this, name, definition)); } From 5038b22a6c166a0239ebac40c845a5c811dcc996 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 30 May 2023 12:08:48 -0600 Subject: [PATCH 19/24] address Neal's comments --- src/collection.ts | 8 +++----- src/operations/search_indexes/create.ts | 4 ++-- src/operations/search_indexes/drop.ts | 4 ++-- src/operations/search_indexes/list.ts | 6 ++---- src/operations/search_indexes/update.ts | 3 ++- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/collection.ts b/src/collection.ts index 9f5f73950b9..b2695e6f7de 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -1042,8 +1042,8 @@ export class Collection { * @remarks Only available when used against a 7.0+ Atlas cluster. */ async createSearchIndex(description: SearchIndexDescription): Promise { - const indexes = await this.createSearchIndexes([description]); - return indexes[0]; + const [index] = await this.createSearchIndexes([description]); + return index; } /** @@ -1057,9 +1057,7 @@ export class Collection { * @remarks Only available when used against a 7.0+ Atlas cluster. * @returns */ - async createSearchIndexes( - descriptions: ReadonlyArray - ): Promise { + async createSearchIndexes(descriptions: SearchIndexDescription[]): Promise { return executeOperation(this.client, new CreateSearchIndexesOperation(this, descriptions)); } diff --git a/src/operations/search_indexes/create.ts b/src/operations/search_indexes/create.ts index 121acab1273..9cd20e2f24c 100644 --- a/src/operations/search_indexes/create.ts +++ b/src/operations/search_indexes/create.ts @@ -18,13 +18,13 @@ export interface SearchIndexDescription { /** @internal */ export class CreateSearchIndexesOperation extends AbstractOperation { constructor( - private readonly collection: Collection, + private readonly collection: Collection, private readonly descriptions: ReadonlyArray ) { super(); } - execute(server: Server, session: ClientSession | undefined, callback: Callback): void { + execute(server: Server, session: ClientSession | undefined, callback: Callback): void { const namespace = this.collection.fullNamespace; const command = { createSearchIndexes: namespace.collection, diff --git a/src/operations/search_indexes/drop.ts b/src/operations/search_indexes/drop.ts index 27c4898a140..4e3ed88c114 100644 --- a/src/operations/search_indexes/drop.ts +++ b/src/operations/search_indexes/drop.ts @@ -6,9 +6,9 @@ import type { ClientSession } from '../../sessions'; import type { Callback } from '../../utils'; import { AbstractOperation } from '../operation'; +/** @internal */ export class DropSearchIndexOperation extends AbstractOperation { - /** @internal */ - constructor(private readonly collection: Collection, private readonly name: string) { + constructor(private readonly collection: Collection, private readonly name: string) { super(); } diff --git a/src/operations/search_indexes/list.ts b/src/operations/search_indexes/list.ts index 0bf537878f3..3ceb14d3e74 100644 --- a/src/operations/search_indexes/list.ts +++ b/src/operations/search_indexes/list.ts @@ -1,5 +1,3 @@ -import type { Document } from 'bson'; - import type { Collection } from '../../collection'; import { AggregationCursor } from '../../cursor/aggregation_cursor'; import type { AggregateOptions } from '../aggregate'; @@ -10,8 +8,8 @@ export type ListSearchIndexesOptions = AggregateOptions; /** @public */ export class ListSearchIndexesCursor extends AggregationCursor<{ name: string }> { /** @internal */ - static create( - { fullNamespace: ns, client }: Collection, + static create( + { fullNamespace: ns, client }: Collection, name: string | null, options: ListSearchIndexesOptions = {} ): ListSearchIndexesCursor { diff --git a/src/operations/search_indexes/update.ts b/src/operations/search_indexes/update.ts index 4875eeb576c..0ed63450c34 100644 --- a/src/operations/search_indexes/update.ts +++ b/src/operations/search_indexes/update.ts @@ -6,9 +6,10 @@ import type { ClientSession } from '../../sessions'; import type { Callback } from '../../utils'; import { AbstractOperation } from '../operation'; +/** @internal */ export class UpdateSearchIndexOperation extends AbstractOperation { constructor( - private readonly collection: Collection, + private readonly collection: Collection, private readonly name: string, private readonly definition: Document ) { From bf440983a810970f8ffad84a8d3911a70fb70012 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 30 May 2023 13:36:03 -0600 Subject: [PATCH 20/24] address Neal's comments pt 2 --- src/admin.ts | 10 ++-- src/bulk/common.ts | 8 ++-- src/change_stream.ts | 4 +- src/collection.ts | 46 +++++++++++++------ src/cursor/list_collections_cursor.ts | 4 +- src/cursor/list_indexes_cursor.ts | 4 +- .../list_search_indexes_cursor.ts} | 12 ++--- src/db.ts | 15 +++--- src/index.ts | 8 ++-- src/operations/create_collection.ts | 2 +- src/operations/drop.ts | 2 +- src/utils.ts | 6 +-- test/unit/utils.test.ts | 18 +++++++- 13 files changed, 85 insertions(+), 54 deletions(-) rename src/{operations/search_indexes/list.ts => cursor/list_search_indexes_cursor.ts} (58%) diff --git a/src/admin.ts b/src/admin.ts index a6bad5885e0..224deaa54aa 100644 --- a/src/admin.ts +++ b/src/admin.ts @@ -75,7 +75,7 @@ export class Admin { */ async command(command: Document, options?: RunCommandOptions): Promise { return executeOperation( - this.s.db.s.client, + this.s.db.client, new RunCommandOperation(this.s.db, command, { dbName: 'admin', ...options }) ); } @@ -138,7 +138,7 @@ export class Admin { : undefined; const password = typeof passwordOrOptions === 'string' ? passwordOrOptions : undefined; return executeOperation( - this.s.db.s.client, + this.s.db.client, new AddUserOperation(this.s.db, username, password, { dbName: 'admin', ...options }) ); } @@ -151,7 +151,7 @@ export class Admin { */ async removeUser(username: string, options?: RemoveUserOptions): Promise { return executeOperation( - this.s.db.s.client, + this.s.db.client, new RemoveUserOperation(this.s.db, username, { dbName: 'admin', ...options }) ); } @@ -167,7 +167,7 @@ export class Admin { options: ValidateCollectionOptions = {} ): Promise { return executeOperation( - this.s.db.s.client, + this.s.db.client, new ValidateCollectionOperation(this, collectionName, options) ); } @@ -178,7 +178,7 @@ export class Admin { * @param options - Optional settings for the command */ async listDatabases(options?: ListDatabasesOptions): Promise { - return executeOperation(this.s.db.s.client, new ListDatabasesOperation(this.s.db, options)); + return executeOperation(this.s.db.client, new ListDatabasesOperation(this.s.db, options)); } /** diff --git a/src/bulk/common.ts b/src/bulk/common.ts index f8a46a8f14e..7436a88de64 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -597,19 +597,19 @@ function executeCommands( try { if (isInsertBatch(batch)) { executeOperation( - bulkOperation.s.collection.s.db.s.client, + bulkOperation.s.collection.client, new InsertOperation(bulkOperation.s.namespace, batch.operations, finalOptions), resultHandler ); } else if (isUpdateBatch(batch)) { executeOperation( - bulkOperation.s.collection.s.db.s.client, + bulkOperation.s.collection.client, new UpdateOperation(bulkOperation.s.namespace, batch.operations, finalOptions), resultHandler ); } else if (isDeleteBatch(batch)) { executeOperation( - bulkOperation.s.collection.s.db.s.client, + bulkOperation.s.collection.client, new DeleteOperation(bulkOperation.s.namespace, batch.operations, finalOptions), resultHandler ); @@ -1222,7 +1222,7 @@ export abstract class BulkOperationBase { const finalOptions = { ...this.s.options, ...options }; const operation = new BulkWriteShimOperation(this, finalOptions); - return executeOperation(this.s.collection.s.db.s.client, operation); + return executeOperation(this.s.collection.client, operation); } /** diff --git a/src/change_stream.ts b/src/change_stream.ts index ad77624d317..c002c60858a 100644 --- a/src/change_stream.ts +++ b/src/change_stream.ts @@ -818,9 +818,9 @@ export class ChangeStream< this.type === CHANGE_DOMAIN_TYPES.CLUSTER ? (this.parent as MongoClient) : this.type === CHANGE_DOMAIN_TYPES.DATABASE - ? (this.parent as Db).s.client + ? (this.parent as Db).client : this.type === CHANGE_DOMAIN_TYPES.COLLECTION - ? (this.parent as Collection).s.db.s.client + ? (this.parent as Collection).client : null; if (client == null) { diff --git a/src/collection.ts b/src/collection.ts index b2695e6f7de..8736cc2153f 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -6,6 +6,10 @@ import { ChangeStream, ChangeStreamDocument, ChangeStreamOptions } from './chang import { AggregationCursor } from './cursor/aggregation_cursor'; import { FindCursor } from './cursor/find_cursor'; import { ListIndexesCursor } from './cursor/list_indexes_cursor'; +import { + ListSearchIndexesCursor, + ListSearchIndexesOptions +} from './cursor/list_search_indexes_cursor'; import type { Db } from './db'; import { MongoInvalidArgumentError } from './error'; import type { MongoClient, PkFactory } from './mongo_client'; @@ -75,10 +79,6 @@ import { SearchIndexDescription } from './operations/search_indexes/create'; import { DropSearchIndexOperation } from './operations/search_indexes/drop'; -import { - ListSearchIndexesCursor, - ListSearchIndexesOptions -} from './operations/search_indexes/list'; import { UpdateSearchIndexOperation } from './operations/search_indexes/update'; import { CollStats, CollStatsOperation, CollStatsOptions } from './operations/stats'; import { @@ -163,6 +163,9 @@ export class Collection { /** @internal */ s: CollectionPrivate; + /** @internal */ + client: MongoClient; + /** * Create a new Collection instance * @internal @@ -181,11 +184,8 @@ export class Collection { readConcern: ReadConcern.fromOptions(options), writeConcern: WriteConcern.fromOptions(options) }; - } - /** @internal */ - get client(): MongoClient { - return this.s.db.client; + this.client = db.client; } /** @@ -1008,13 +1008,22 @@ export class Collection { * * Returns all search indexes for the current collection. * - * @param indexName - Optional. If specified, only indexes with matching index names will be returned. * @param options - The options for the list indexes operation. * * @remarks Only available when used against a 7.0+ Atlas cluster. */ listSearchIndexes(options?: ListSearchIndexesOptions): ListSearchIndexesCursor; - listSearchIndexes(indexName: string, options?: ListSearchIndexesOptions): ListSearchIndexesCursor; + /** + * @internal + * + * Returns all search indexes for the current collection. + * + * @param name - The name of the index to search for. Only indexes with matching index names will be returned. + * @param options - The options for the list indexes operation. + * + * @remarks Only available when used against a 7.0+ Atlas cluster. + */ + listSearchIndexes(name: string, options?: ListSearchIndexesOptions): ListSearchIndexesCursor; listSearchIndexes( indexNameOrOptions?: string | ListSearchIndexesOptions, options?: ListSearchIndexesOptions @@ -1028,7 +1037,7 @@ export class Collection { ? null : indexNameOrOptions; - return ListSearchIndexesCursor.create(this, indexName, options); + return new ListSearchIndexesCursor(this as TODO_NODE_3286, indexName, options); } /** @@ -1058,7 +1067,10 @@ export class Collection { * @returns */ async createSearchIndexes(descriptions: SearchIndexDescription[]): Promise { - return executeOperation(this.client, new CreateSearchIndexesOperation(this, descriptions)); + return executeOperation( + this.client, + new CreateSearchIndexesOperation(this as TODO_NODE_3286, descriptions) + ); } /** @@ -1071,7 +1083,10 @@ export class Collection { * @remarks Only available when used against a 7.0+ Atlas cluster. */ async dropSearchIndex(name: string): Promise { - return executeOperation(this.client, new DropSearchIndexOperation(this, name)); + return executeOperation( + this.client, + new DropSearchIndexOperation(this as TODO_NODE_3286, name) + ); } /** @@ -1085,6 +1100,9 @@ export class Collection { * @remarks Only available when used against a 7.0+ Atlas cluster. */ async updateSearchIndex(name: string, definition: Document): Promise { - return executeOperation(this.client, new UpdateSearchIndexOperation(this, name, definition)); + return executeOperation( + this.client, + new UpdateSearchIndexOperation(this as TODO_NODE_3286, name, definition) + ); } } diff --git a/src/cursor/list_collections_cursor.ts b/src/cursor/list_collections_cursor.ts index 460126be8a0..0af06df541b 100644 --- a/src/cursor/list_collections_cursor.ts +++ b/src/cursor/list_collections_cursor.ts @@ -21,7 +21,7 @@ export class ListCollectionsCursor< options?: ListCollectionsOptions; constructor(db: Db, filter: Document, options?: ListCollectionsOptions) { - super(db.s.client, db.s.namespace, options); + super(db.client, db.s.namespace, options); this.parent = db; this.filter = filter; this.options = options; @@ -42,7 +42,7 @@ export class ListCollectionsCursor< session }); - executeOperation(this.parent.s.client, operation, (err, response) => { + executeOperation(this.parent.client, operation, (err, response) => { if (err || response == null) return callback(err); // TODO: NODE-2882 diff --git a/src/cursor/list_indexes_cursor.ts b/src/cursor/list_indexes_cursor.ts index 25336d84ddb..4919a0cf16c 100644 --- a/src/cursor/list_indexes_cursor.ts +++ b/src/cursor/list_indexes_cursor.ts @@ -11,7 +11,7 @@ export class ListIndexesCursor extends AbstractCursor { options?: ListIndexesOptions; constructor(collection: Collection, options?: ListIndexesOptions) { - super(collection.s.db.s.client, collection.s.namespace, options); + super(collection.client, collection.s.namespace, options); this.parent = collection; this.options = options; } @@ -31,7 +31,7 @@ export class ListIndexesCursor extends AbstractCursor { session }); - executeOperation(this.parent.s.db.s.client, operation, (err, response) => { + executeOperation(this.parent.client, operation, (err, response) => { if (err || response == null) return callback(err); // TODO: NODE-2882 diff --git a/src/operations/search_indexes/list.ts b/src/cursor/list_search_indexes_cursor.ts similarity index 58% rename from src/operations/search_indexes/list.ts rename to src/cursor/list_search_indexes_cursor.ts index 3ceb14d3e74..bf5a0b56120 100644 --- a/src/operations/search_indexes/list.ts +++ b/src/cursor/list_search_indexes_cursor.ts @@ -1,6 +1,6 @@ -import type { Collection } from '../../collection'; -import { AggregationCursor } from '../../cursor/aggregation_cursor'; -import type { AggregateOptions } from '../aggregate'; +import type { Collection } from '../collection'; +import type { AggregateOptions } from '../operations/aggregate'; +import { AggregationCursor } from './aggregation_cursor'; /** @public */ export type ListSearchIndexesOptions = AggregateOptions; @@ -8,13 +8,13 @@ export type ListSearchIndexesOptions = AggregateOptions; /** @public */ export class ListSearchIndexesCursor extends AggregationCursor<{ name: string }> { /** @internal */ - static create( + constructor( { fullNamespace: ns, client }: Collection, name: string | null, options: ListSearchIndexesOptions = {} - ): ListSearchIndexesCursor { + ) { const pipeline = name == null ? [{ $listSearchIndexes: {} }] : [{ $listSearchIndexes: { name } }]; - return new ListSearchIndexesCursor(client, ns, pipeline, options); + super(client, ns, pipeline, options); } } diff --git a/src/db.ts b/src/db.ts index db6f45ccfe8..0e52b1d6955 100644 --- a/src/db.ts +++ b/src/db.ts @@ -70,7 +70,6 @@ const DB_OPTIONS_ALLOW_LIST = [ /** @internal */ export interface DbPrivate { - client: MongoClient; options?: DbOptions; readPreference?: ReadPreference; pkFactory: PkFactory; @@ -136,7 +135,12 @@ export class Db { * @param databaseName - The name of the database this instance represents. * @param options - Optional settings for Db construction */ - constructor(client: MongoClient, databaseName: string, options?: DbOptions) { + constructor( + /** @internal */ + readonly client: MongoClient, + databaseName: string, + options?: DbOptions + ) { options = options ?? {}; // Filter the options @@ -147,8 +151,6 @@ export class Db { // Internal state of the db object this.s = { - // Client - client, // Options options, // Unpack read preference @@ -163,11 +165,8 @@ export class Db { // Namespace namespace: new MongoDBNamespace(databaseName) }; - } - /** @internal */ - get client(): MongoClient { - return this.s.client; + this.client = client; } get databaseName(): string { diff --git a/src/index.ts b/src/index.ts index 377216bb42b..12346002ed3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -277,6 +277,10 @@ export type { ChangeStreamAggregateRawResult, ChangeStreamCursorOptions } from './cursor/change_stream_cursor'; +export type { + ListSearchIndexesCursor, + ListSearchIndexesOptions +} from './cursor/list_search_indexes_cursor'; export type { RunCursorCommandOptions } from './cursor/run_command_cursor'; export type { DbOptions, DbPrivate } from './db'; export type { AutoEncrypter, AutoEncryptionOptions, AutoEncryptionTlsOptions } from './deps'; @@ -419,10 +423,6 @@ export type { RemoveUserOptions } from './operations/remove_user'; export type { RenameOptions } from './operations/rename'; export type { RunCommandOptions } from './operations/run_command'; export type { SearchIndexDescription } from './operations/search_indexes/create'; -export type { - ListSearchIndexesCursor, - ListSearchIndexesOptions -} from './operations/search_indexes/list'; export type { SetProfilingLevelOptions } from './operations/set_profiling_level'; export type { CollStats, diff --git a/src/operations/create_collection.ts b/src/operations/create_collection.ts index ebc99bc6002..bd0af76424b 100644 --- a/src/operations/create_collection.ts +++ b/src/operations/create_collection.ts @@ -133,7 +133,7 @@ export class CreateCollectionOperation extends CommandOperation { const encryptedFields: Document | undefined = options.encryptedFields ?? - db.s.client.options.autoEncryption?.encryptedFieldsMap?.[`${db.databaseName}.${name}`]; + db.client.options.autoEncryption?.encryptedFieldsMap?.[`${db.databaseName}.${name}`]; if (encryptedFields) { // Creating a QE collection required min server of 7.0.0 diff --git a/src/operations/drop.ts b/src/operations/drop.ts index b22fe65cde7..65e2f95485f 100644 --- a/src/operations/drop.ts +++ b/src/operations/drop.ts @@ -36,7 +36,7 @@ export class DropCollectionOperation extends CommandOperation { const options = this.options; const name = this.name; - const encryptedFieldsMap = db.s.client.options.autoEncryption?.encryptedFieldsMap; + const encryptedFieldsMap = db.client.options.autoEncryption?.encryptedFieldsMap; let encryptedFields: Document | undefined = options.encryptedFields ?? encryptedFieldsMap?.[`${db.databaseName}.${name}`]; diff --git a/src/utils.ts b/src/utils.ts index e929cd3b1aa..6c0c08737e5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -288,10 +288,8 @@ export function getTopology(provider: TopologyProvider): Topology { // MongoClient or ClientSession or AbstractCursor if ('topology' in provider && provider.topology) { return provider.topology; - } else if ('s' in provider && 'client' in provider.s && provider.s.client.topology) { - return provider.s.client.topology; - } else if ('s' in provider && 'db' in provider.s && provider.s.db.s.client.topology) { - return provider.s.db.s.client.topology; + } else if ('client' in provider && provider.client.topology) { + return provider.client.topology; } throw new MongoNotConnectedError('MongoClient must be connected to perform this operation'); diff --git a/test/unit/utils.test.ts b/test/unit/utils.test.ts index 519aef78458..9ebf0d59693 100644 --- a/test/unit/utils.test.ts +++ b/test/unit/utils.test.ts @@ -12,13 +12,14 @@ import { List, matchesParentDomain, maybeCallback, + MongoDBCollectionNamespace, MongoDBNamespace, MongoRuntimeError, ObjectId, shuffle } from '../mongodb'; -describe('driver utils', function () { +describe.only('driver utils', function () { describe('.hostMatchesWildcards', function () { context('when using domains', function () { context('when using exact match', function () { @@ -772,6 +773,21 @@ describe('driver utils', function () { expect(withCollectionNamespace).to.have.property('db', 'test'); expect(withCollectionNamespace).to.have.property('collection', 'pets'); }); + + it('returns a MongoDBCollectionNamespaceObject', () => { + expect(dbNamespace.withCollection('pets')).to.be.instanceOf(MongoDBCollectionNamespace); + }); + }); + }); + + describe('MongoDBCollectionNamespace', () => { + it('is a subclass of MongoDBNamespace', () => { + expect(new MongoDBCollectionNamespace('db', 'collection')).to.be.instanceOf(MongoDBNamespace); + }); + + it('does not enforce the collection property at runtime', () => { + // @ts-expect-error Intentionally calling constructor incorrectly. + expect(new MongoDBCollectionNamespace('db')).to.have.property('collection', undefined); }); }); From fb4a8c7028f3a338e3accf45750a580a3179fbff Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 30 May 2023 13:43:48 -0600 Subject: [PATCH 21/24] cleanups --- package.json | 2 +- src/db.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index b8b9c087ee9..dccfc836e31 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ "check:tsd": "tsd --version && tsd", "check:dependencies": "mocha test/action/dependency.test.ts", "check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd", - "check:search-indexes": "mocha --config test/mocha_mongodb.json test/manual/search-index-management.spec.test.ts", + "check:search-indexes": "nyc mocha --config test/mocha_mongodb.json test/manual/search-index-management.spec.test.ts", "check:test": "mocha --config test/mocha_mongodb.json test/integration", "check:unit": "mocha test/unit", "check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit", diff --git a/src/db.ts b/src/db.ts index 0e52b1d6955..711aff07d0a 100644 --- a/src/db.ts +++ b/src/db.ts @@ -165,8 +165,6 @@ export class Db { // Namespace namespace: new MongoDBNamespace(databaseName) }; - - this.client = client; } get databaseName(): string { From c67c717e7018c0a1244708b7badeed1eb7940562 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 30 May 2023 21:57:31 -0600 Subject: [PATCH 22/24] address comments --- src/cursor/list_search_indexes_cursor.ts | 4 ++-- src/db.ts | 12 ++++++------ src/operations/search_indexes/create.ts | 2 +- test/unit/utils.test.ts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cursor/list_search_indexes_cursor.ts b/src/cursor/list_search_indexes_cursor.ts index bf5a0b56120..285af02ef3c 100644 --- a/src/cursor/list_search_indexes_cursor.ts +++ b/src/cursor/list_search_indexes_cursor.ts @@ -2,10 +2,10 @@ import type { Collection } from '../collection'; import type { AggregateOptions } from '../operations/aggregate'; import { AggregationCursor } from './aggregation_cursor'; -/** @public */ +/** @internal */ export type ListSearchIndexesOptions = AggregateOptions; -/** @public */ +/** @internal */ export class ListSearchIndexesCursor extends AggregationCursor<{ name: string }> { /** @internal */ constructor( diff --git a/src/db.ts b/src/db.ts index 711aff07d0a..1d02649e044 100644 --- a/src/db.ts +++ b/src/db.ts @@ -121,6 +121,9 @@ export class Db { /** @internal */ s: DbPrivate; + /** @internal */ + readonly client: MongoClient; + public static SYSTEM_NAMESPACE_COLLECTION = CONSTANTS.SYSTEM_NAMESPACE_COLLECTION; public static SYSTEM_INDEX_COLLECTION = CONSTANTS.SYSTEM_INDEX_COLLECTION; public static SYSTEM_PROFILE_COLLECTION = CONSTANTS.SYSTEM_PROFILE_COLLECTION; @@ -135,12 +138,7 @@ export class Db { * @param databaseName - The name of the database this instance represents. * @param options - Optional settings for Db construction */ - constructor( - /** @internal */ - readonly client: MongoClient, - databaseName: string, - options?: DbOptions - ) { + constructor(client: MongoClient, databaseName: string, options?: DbOptions) { options = options ?? {}; // Filter the options @@ -165,6 +163,8 @@ export class Db { // Namespace namespace: new MongoDBNamespace(databaseName) }; + + this.client = client; } get databaseName(): string { diff --git a/src/operations/search_indexes/create.ts b/src/operations/search_indexes/create.ts index 9cd20e2f24c..cce926de88c 100644 --- a/src/operations/search_indexes/create.ts +++ b/src/operations/search_indexes/create.ts @@ -6,7 +6,7 @@ import type { ClientSession } from '../../sessions'; import type { Callback } from '../../utils'; import { AbstractOperation } from '../operation'; -/** @public */ +/** @internal */ export interface SearchIndexDescription { /** The name of the index. */ name?: string; diff --git a/test/unit/utils.test.ts b/test/unit/utils.test.ts index 9ebf0d59693..e3d82c50bde 100644 --- a/test/unit/utils.test.ts +++ b/test/unit/utils.test.ts @@ -19,7 +19,7 @@ import { shuffle } from '../mongodb'; -describe.only('driver utils', function () { +describe('driver utils', function () { describe('.hostMatchesWildcards', function () { context('when using domains', function () { context('when using exact match', function () { From b66854c462fff005f92b6453f2ef8152748421cd Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 31 May 2023 11:15:35 -0600 Subject: [PATCH 23/24] account for Neal's runcommandcursor changes --- src/cursor/run_command_cursor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cursor/run_command_cursor.ts b/src/cursor/run_command_cursor.ts index 95dcef49837..9dbc85b2d41 100644 --- a/src/cursor/run_command_cursor.ts +++ b/src/cursor/run_command_cursor.ts @@ -96,7 +96,7 @@ export class RunCommandCursor extends AbstractCursor { /** @internal */ constructor(db: Db, command: Document, options: RunCursorCommandOptions = {}) { - super(db.s.client, ns(db.namespace), options); + super(db.client, ns(db.namespace), options); this.db = db; this.command = Object.freeze({ ...command }); } From 28ff583e14fc9de30fa02672fdc1762c445c1676 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Wed, 31 May 2023 11:53:47 -0600 Subject: [PATCH 24/24] rebuild config --- .evergreen/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 7be9befa70f..52833baf665 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -2602,7 +2602,7 @@ tasks: commands: - func: install dependencies vars: - NODE_LTS_NAME: hydrogen + NODE_LTS_NAME: 20 - func: bootstrap mongo-orchestration vars: VERSION: latest