Skip to content

Commit 935f24a

Browse files
remove 'IndexExistsOperation'
1 parent d45cdbc commit 935f24a

File tree

3 files changed

+8
-49
lines changed

3 files changed

+8
-49
lines changed

src/collection.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import {
5555
type DropIndexesOptions,
5656
DropIndexOperation,
5757
type IndexDescription,
58-
IndexExistsOperation,
5958
IndexInformationOperation,
6059
type IndexSpecification,
6160
type ListIndexesOptions
@@ -91,7 +90,8 @@ import {
9190
DEFAULT_PK_FACTORY,
9291
MongoDBCollectionNamespace,
9392
normalizeHintField,
94-
resolveOptions
93+
resolveOptions,
94+
setDifference
9595
} from './utils';
9696
import { WriteConcern, type WriteConcernOptions } from './write_concern';
9797

@@ -684,10 +684,12 @@ export class Collection<TSchema extends Document = Document> {
684684
indexes: string | string[],
685685
options?: IndexInformationOptions
686686
): Promise<boolean> {
687-
return executeOperation(
688-
this.client,
689-
new IndexExistsOperation(this as TODO_NODE_3286, indexes, resolveOptions(this, options))
690-
);
687+
const indexNames: Set<string> = new Set([indexes].flat());
688+
const allIndexes: string[] = await this.listIndexes(options)
689+
.map(({ name }) => name)
690+
.toArray();
691+
692+
return setDifference(indexNames, allIndexes).size === 0;
691693
}
692694

693695
/**

src/operations/indexes.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -337,43 +337,6 @@ export class ListIndexesOperation extends CommandOperation<Document> {
337337
}
338338
}
339339

340-
/** @internal */
341-
export class IndexExistsOperation extends AbstractOperation<boolean> {
342-
override options: IndexInformationOptions;
343-
collection: Collection;
344-
indexes: string | string[];
345-
346-
constructor(
347-
collection: Collection,
348-
indexes: string | string[],
349-
options: IndexInformationOptions
350-
) {
351-
super(options);
352-
this.options = options;
353-
this.collection = collection;
354-
this.indexes = indexes;
355-
}
356-
357-
override get commandName() {
358-
return 'listIndexes' as const;
359-
}
360-
361-
override async execute(server: Server, session: ClientSession | undefined): Promise<boolean> {
362-
const coll = this.collection;
363-
const indexes = this.indexes;
364-
365-
const info = await indexInformation(coll.s.db, coll.collectionName, {
366-
...this.options,
367-
readPreference: this.readPreference,
368-
session
369-
});
370-
// Let's check for the index names
371-
if (!Array.isArray(indexes)) return info[indexes] != null;
372-
// All keys found return true
373-
return indexes.every(indexName => info[indexName] != null);
374-
}
375-
}
376-
377340
/** @internal */
378341
export class IndexInformationOperation extends AbstractOperation<Document> {
379342
override options: IndexInformationOptions;

test/integration/crud/abstract_operation.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ describe('abstract operation', async function () {
1919
'OptionsOperation',
2020
'IsCappedOperation',
2121
'BulkWriteOperation',
22-
'IndexExistsOperation',
2322
'IndexOperation',
2423
'CollectionsOperation',
2524
'IndexInformationOperation'
@@ -157,11 +156,6 @@ describe('abstract operation', async function () {
157156
subclassType: mongodb.ListIndexesOperation,
158157
correctCommandName: 'listIndexes'
159158
},
160-
{
161-
subclassCreator: () => new mongodb.IndexExistsOperation(collection, 'a', {}),
162-
subclassType: mongodb.IndexExistsOperation,
163-
correctCommandName: 'listIndexes'
164-
},
165159
{
166160
subclassCreator: () => new mongodb.IndexInformationOperation(db, 'a', {}),
167161
subclassType: mongodb.IndexInformationOperation,

0 commit comments

Comments
 (0)