Skip to content

Commit 87a4e0a

Browse files
remove index information utility
1 parent 595aae4 commit 87a4e0a

File tree

5 files changed

+22
-54
lines changed

5 files changed

+22
-54
lines changed

src/collection.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type {
2424
} from './mongo_types';
2525
import type { AggregateOptions } from './operations/aggregate';
2626
import { BulkWriteOperation } from './operations/bulk_write';
27-
import type { IndexInformationOptions } from './operations/common_functions';
2827
import { CountOperation, type CountOptions } from './operations/count';
2928
import { CountDocumentsOperation, type CountDocumentsOptions } from './operations/count_documents';
3029
import {
@@ -49,15 +48,15 @@ import {
4948
FindOneAndUpdateOperation,
5049
type FindOneAndUpdateOptions
5150
} from './operations/find_and_modify';
52-
import {
53-
CreateIndexesOperation,
54-
type CreateIndexesOptions,
55-
type DropIndexesOptions,
56-
DropIndexOperation,
57-
type IndexDescription,
58-
type IndexSpecification,
59-
type ListIndexesOptions
51+
import type {
52+
CreateIndexesOptions,
53+
DropIndexesOptions,
54+
IndexDescription,
55+
IndexInformationOptions,
56+
IndexSpecification,
57+
ListIndexesOptions
6058
} from './operations/indexes';
59+
import { CreateIndexesOperation, DropIndexOperation } from './operations/indexes';
6160
import {
6261
InsertManyOperation,
6362
type InsertManyResult,

src/db.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type { MongoClient, PkFactory } from './mongo_client';
1111
import type { TODO_NODE_3286 } from './mongo_types';
1212
import type { AggregateOptions } from './operations/aggregate';
1313
import { CollectionsOperation } from './operations/collections';
14-
import type { IndexInformationOptions } from './operations/common_functions';
1514
import {
1615
CreateCollectionOperation,
1716
type CreateCollectionOptions
@@ -23,7 +22,11 @@ import {
2322
type DropDatabaseOptions
2423
} from './operations/drop';
2524
import { executeOperation } from './operations/execute_operation';
26-
import { type CreateIndexesOptions, type IndexSpecification } from './operations/indexes';
25+
import type {
26+
CreateIndexesOptions,
27+
IndexInformationOptions,
28+
IndexSpecification
29+
} from './operations/indexes';
2730
import type { CollectionInfo, ListCollectionsOptions } from './operations/list_collections';
2831
import { ProfilingLevelOperation, type ProfilingLevelOptions } from './operations/profiling_level';
2932
import { RemoveUserOperation, type RemoveUserOptions } from './operations/remove_user';

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ export type {
447447
CommandOperationOptions,
448448
OperationParent
449449
} from './operations/command';
450-
export type { IndexInformationOptions } from './operations/common_functions';
451450
export type { CountOptions } from './operations/count';
452451
export type { CountDocumentsOptions } from './operations/count_documents';
453452
export type {
@@ -466,6 +465,7 @@ export type {
466465
FindOneAndReplaceOptions,
467466
FindOneAndUpdateOptions
468467
} from './operations/find_and_modify';
468+
export type { IndexInformationOptions } from './operations/indexes';
469469
export type {
470470
CreateIndexesOptions,
471471
DropIndexesOptions,

src/operations/common_functions.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,5 @@
11
import type { Document } from '../bson';
22
import type { Collection } from '../collection';
3-
import type { Db } from '../db';
4-
import type { ReadPreference } from '../read_preference';
5-
import type { ClientSession } from '../sessions';
6-
7-
/** @public */
8-
export interface IndexInformationOptions {
9-
full?: boolean;
10-
readPreference?: ReadPreference;
11-
session?: ClientSession;
12-
}
13-
/**
14-
* Retrieves this collections index info.
15-
*
16-
* @param db - The Db instance on which to retrieve the index info.
17-
* @param name - The name of the collection.
18-
*/
19-
export async function indexInformation(db: Db, name: string): Promise<any>;
20-
export async function indexInformation(
21-
db: Db,
22-
name: string,
23-
options?: IndexInformationOptions
24-
): Promise<any>;
25-
export async function indexInformation(
26-
db: Db,
27-
name: string,
28-
options?: IndexInformationOptions
29-
): Promise<any> {
30-
if (options == null) {
31-
options = {};
32-
}
33-
// If we specified full information
34-
const full = options.full == null ? false : options.full;
35-
// Get the list of indexes of the specified collection
36-
const indexes = await db.collection(name).listIndexes(options).toArray();
37-
if (full) return indexes;
38-
39-
const info: Record<string, Array<[string, unknown]>> = {};
40-
for (const index of indexes) {
41-
info[index.name] = Object.entries(index.key);
42-
}
43-
return info;
44-
}
453

464
export function maybeAddIdToDocuments(
475
coll: Collection,

src/operations/indexes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Document } from '../bson';
22
import type { Collection } from '../collection';
33
import { MongoCompatibilityError } from '../error';
44
import { type OneOrMore } from '../mongo_types';
5+
import { type ReadPreference } from '../read_preference';
56
import type { Server } from '../sdam/server';
67
import type { ClientSession } from '../sessions';
78
import { isObject, maxWireVersion, type MongoDBNamespace } from '../utils';
@@ -70,6 +71,13 @@ export type IndexSpecification = OneOrMore<
7071
| Map<string, IndexDirection>
7172
>;
7273

74+
/** @public */
75+
export interface IndexInformationOptions {
76+
full?: boolean;
77+
readPreference?: ReadPreference;
78+
session?: ClientSession;
79+
}
80+
7381
/** @public */
7482
export interface IndexDescription
7583
extends Pick<

0 commit comments

Comments
 (0)