Skip to content

Commit 4930d0e

Browse files
misc correctness fixes
1 parent 87a4e0a commit 4930d0e

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Diff for: src/collection.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,13 @@ export class Collection<TSchema extends Document = Document> {
683683
options?: IndexInformationOptions
684684
): Promise<boolean> {
685685
const indexNames: string[] = [indexes].flat();
686-
const allIndexes: string[] = await this.listIndexes(options)
687-
.map(({ name }) => name)
688-
.toArray();
686+
const allIndexes: Set<string> = new Set(
687+
await this.listIndexes(options)
688+
.map(({ name }) => name)
689+
.toArray()
690+
);
689691

690-
return setDifference(indexNames, allIndexes).size === 0;
692+
return indexNames.every(name => allIndexes.has(name));
691693
}
692694

693695
/**
@@ -696,12 +698,7 @@ export class Collection<TSchema extends Document = Document> {
696698
* @param options - Optional settings for the command
697699
*/
698700
async indexInformation(options?: IndexInformationOptions): Promise<Document> {
699-
const resolvedOptions: IndexInformationOptions = {
700-
readPreference: options?.readPreference,
701-
session: options?.session,
702-
full: false
703-
};
704-
return this.indexes(resolvedOptions);
701+
return this.indexes({ ...options, full: options?.full ?? false });
705702
}
706703

707704
/**
@@ -807,7 +804,7 @@ export class Collection<TSchema extends Document = Document> {
807804
*/
808805
async indexes(options?: IndexInformationOptions): Promise<Document[]> {
809806
const indexes = await this.listIndexes(options).toArray();
810-
const full = options?.full === true;
807+
const full = options?.full ?? true === true;
811808
if (full) {
812809
return indexes;
813810
}

0 commit comments

Comments
 (0)