Skip to content

Commit c536534

Browse files
refactor(NODE-5774): remove IsCappedOperation, CollectionsOperation and OptionsOperation (#4603)
1 parent e0352c0 commit c536534

File tree

7 files changed

+22
-151
lines changed

7 files changed

+22
-151
lines changed

src/collection.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
type ListSearchIndexesOptions
1717
} from './cursor/list_search_indexes_cursor';
1818
import type { Db } from './db';
19-
import { MongoInvalidArgumentError, MongoOperationTimeoutError } from './error';
19+
import { MongoAPIError, MongoInvalidArgumentError, MongoOperationTimeoutError } from './error';
2020
import type { MongoClient, PkFactory } from './mongo_client';
2121
import type {
2222
Abortable,
@@ -70,9 +70,7 @@ import {
7070
type InsertOneOptions,
7171
type InsertOneResult
7272
} from './operations/insert';
73-
import { IsCappedOperation } from './operations/is_capped';
7473
import type { Hint, OperationOptions } from './operations/operation';
75-
import { OptionsOperation } from './operations/options_operation';
7674
import { RenameOperation, type RenameOptions } from './operations/rename';
7775
import {
7876
CreateSearchIndexesOperation,
@@ -591,10 +589,16 @@ export class Collection<TSchema extends Document = Document> {
591589
* @param options - Optional settings for the command
592590
*/
593591
async options(options?: OperationOptions): Promise<Document> {
594-
return await executeOperation(
595-
this.client,
596-
new OptionsOperation(this as TODO_NODE_3286, resolveOptions(this, options))
597-
);
592+
options = resolveOptions(this, options);
593+
const [collection] = await this.s.db
594+
.listCollections({ name: this.collectionName }, { ...options, nameOnly: false })
595+
.toArray();
596+
597+
if (collection == null || collection.options == null) {
598+
throw new MongoAPIError(`collection ${this.namespace} not found`);
599+
}
600+
601+
return collection.options;
598602
}
599603

600604
/**
@@ -603,10 +607,8 @@ export class Collection<TSchema extends Document = Document> {
603607
* @param options - Optional settings for the command
604608
*/
605609
async isCapped(options?: OperationOptions): Promise<boolean> {
606-
return await executeOperation(
607-
this.client,
608-
new IsCappedOperation(this as TODO_NODE_3286, resolveOptions(this, options))
609-
);
610+
const { capped } = await this.options(options);
611+
return Boolean(capped);
610612
}
611613

612614
/**

src/db.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { MongoInvalidArgumentError } from './error';
1010
import type { MongoClient, PkFactory } from './mongo_client';
1111
import type { Abortable, TODO_NODE_3286 } from './mongo_types';
1212
import type { AggregateOptions } from './operations/aggregate';
13-
import { CollectionsOperation } from './operations/collections';
1413
import {
1514
CreateCollectionOperation,
1615
type CreateCollectionOptions
@@ -435,10 +434,15 @@ export class Db {
435434
* @param options - Optional settings for the command
436435
*/
437436
async collections(options?: ListCollectionsOptions): Promise<Collection[]> {
438-
return await executeOperation(
439-
this.client,
440-
new CollectionsOperation(this, resolveOptions(this, options))
441-
);
437+
options = resolveOptions(this, options);
438+
const collections = await this.listCollections({}, { ...options, nameOnly: true }).toArray();
439+
440+
return collections
441+
.filter(
442+
// Filter collections removing any illegal ones
443+
({ name }) => !name.includes('$')
444+
)
445+
.map(({ name }) => new Collection(this, name, this.s.options));
442446
}
443447

444448
/**

src/operations/collections.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/operations/is_capped.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/operations/options_operation.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/integration/crud/abstract_operation.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ describe('abstract operation', function () {
3737
subclassType: mongodb.AggregateOperation,
3838
correctCommandName: 'aggregate'
3939
},
40-
{
41-
subclassCreator: () => new mongodb.CollectionsOperation(db, {}),
42-
subclassType: mongodb.CollectionsOperation,
43-
correctCommandName: 'listCollections'
44-
},
4540
{
4641
subclassCreator: () => new mongodb.CountOperation(collection.fullNamespace, { a: 1 }, {}),
4742
subclassType: mongodb.CountOperation,
@@ -155,11 +150,6 @@ describe('abstract operation', function () {
155150
subclassType: mongodb.InsertOneOperation,
156151
correctCommandName: 'insert'
157152
},
158-
{
159-
subclassCreator: () => new mongodb.IsCappedOperation(collection, {}),
160-
subclassType: mongodb.IsCappedOperation,
161-
correctCommandName: 'listCollections'
162-
},
163153
{
164154
subclassCreator: () =>
165155
new mongodb.KillCursorsOperation(
@@ -181,11 +171,6 @@ describe('abstract operation', function () {
181171
subclassType: mongodb.ListDatabasesOperation,
182172
correctCommandName: 'listDatabases'
183173
},
184-
{
185-
subclassCreator: () => new mongodb.OptionsOperation(collection, {}),
186-
subclassType: mongodb.OptionsOperation,
187-
correctCommandName: 'listCollections'
188-
},
189174
{
190175
subclassCreator: () => new mongodb.ProfilingLevelOperation(db, {}),
191176
subclassType: mongodb.ProfilingLevelOperation,

test/mongodb.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ export * from '../src/operations/aggregate';
166166
export * from '../src/operations/client_bulk_write/command_builder';
167167
export * from '../src/operations/client_bulk_write/common';
168168
export * from '../src/operations/client_bulk_write/results_merger';
169-
export * from '../src/operations/collections';
170169
export * from '../src/operations/command';
171170
export * from '../src/operations/count';
172171
export * from '../src/operations/create_collection';
@@ -180,12 +179,10 @@ export * from '../src/operations/find_and_modify';
180179
export * from '../src/operations/get_more';
181180
export * from '../src/operations/indexes';
182181
export * from '../src/operations/insert';
183-
export * from '../src/operations/is_capped';
184182
export * from '../src/operations/kill_cursors';
185183
export * from '../src/operations/list_collections';
186184
export * from '../src/operations/list_databases';
187185
export * from '../src/operations/operation';
188-
export * from '../src/operations/options_operation';
189186
export * from '../src/operations/profiling_level';
190187
export * from '../src/operations/remove_user';
191188
export * from '../src/operations/rename';

0 commit comments

Comments
 (0)