Skip to content

Commit cf3906b

Browse files
address comments and fix CI
1 parent dd3e4ef commit cf3906b

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

Diff for: src/collection.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import type {
5252
CreateIndexesOptions,
5353
DropIndexesOptions,
5454
IndexDescription,
55+
IndexDirection,
5556
IndexInformationOptions,
5657
IndexSpecification,
5758
ListIndexesOptions
@@ -682,11 +683,12 @@ export class Collection<TSchema extends Document = Document> {
682683
options?: IndexInformationOptions
683684
): Promise<boolean> {
684685
const indexNames: string[] = Array.isArray(indexes) ? indexes : [indexes];
685-
const allIndexes: string[] = await this.listIndexes(options)
686-
.map(({ name }) => name)
687-
.toArray();
688-
689-
return indexNames.every(name => allIndexes.includes(name));
686+
const allIndexes: Set<string> = new Set(
687+
await this.listIndexes(options)
688+
.map(({ name }) => name)
689+
.toArray()
690+
);
691+
return indexNames.every(name => allIndexes.has(name));
690692
}
691693

692694
/**
@@ -806,9 +808,10 @@ export class Collection<TSchema extends Document = Document> {
806808
return indexes;
807809
}
808810

809-
const object: Record<string, Array<[string, unknown]>> = Object.fromEntries(
810-
indexes.map(({ name, key }) => [name, Object.entries(key)])
811-
);
811+
const object: Record<
812+
string,
813+
Array<[name: string, direction: IndexDirection]>
814+
> = Object.fromEntries(indexes.map(({ name, key }) => [name, Object.entries(key)]));
812815

813816
// @ts-expect-error TODO(NODE-6029): fix return type of `indexes()` and `indexInformation()`
814817
return object;

Diff for: src/db.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import {
2222
type DropDatabaseOptions
2323
} from './operations/drop';
2424
import { executeOperation } from './operations/execute_operation';
25-
import type {
26-
CreateIndexesOptions,
27-
IndexInformationOptions,
28-
IndexSpecification
25+
import {
26+
CreateIndexesOperation,
27+
type CreateIndexesOptions,
28+
type IndexInformationOptions,
29+
type IndexSpecification
2930
} from './operations/indexes';
3031
import type { CollectionInfo, ListCollectionsOptions } from './operations/list_collections';
3132
import { ProfilingLevelOperation, type ProfilingLevelOptions } from './operations/profiling_level';
@@ -424,7 +425,11 @@ export class Db {
424425
indexSpec: IndexSpecification,
425426
options?: CreateIndexesOptions
426427
): Promise<string> {
427-
return this.collection(name).createIndex(indexSpec, options);
428+
const indexes = await executeOperation(
429+
this.client,
430+
CreateIndexesOperation.fromIndexSpecification(this, name, indexSpec, options)
431+
);
432+
return indexes[0];
428433
}
429434

430435
/**

Diff for: src/operations/create_collection.ts

-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ export class CreateCollectionOperation extends CommandOperation<Collection> {
167167

168168
if (encryptedFields) {
169169
// Create the required index for queryable encryption support.
170-
// We could use `this.db.collection(name).createIndex()` to create the index,
171-
// but we can use the same session & server to avoid an extra server selection.
172170
const createIndexOp = CreateIndexesOperation.fromIndexSpecification(
173171
db,
174172
name,

Diff for: test/mongodb.ts

-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ export * from '../src/operations/aggregate';
155155
export * from '../src/operations/bulk_write';
156156
export * from '../src/operations/collections';
157157
export * from '../src/operations/command';
158-
export * from '../src/operations/common_functions';
159158
export * from '../src/operations/count';
160159
export * from '../src/operations/count_documents';
161160
export * from '../src/operations/create_collection';

0 commit comments

Comments
 (0)