Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
type ListSearchIndexesOptions
} from './cursor/list_search_indexes_cursor';
import type { Db } from './db';
import { MongoInvalidArgumentError, MongoOperationTimeoutError } from './error';
import { MongoAPIError, MongoInvalidArgumentError, MongoOperationTimeoutError } from './error';
import type { MongoClient, PkFactory } from './mongo_client';
import type {
Abortable,
Expand Down Expand Up @@ -70,9 +70,7 @@ import {
type InsertOneOptions,
type InsertOneResult
} from './operations/insert';
import { IsCappedOperation } from './operations/is_capped';
import type { Hint, OperationOptions } from './operations/operation';
import { OptionsOperation } from './operations/options_operation';
import { RenameOperation, type RenameOptions } from './operations/rename';
import {
CreateSearchIndexesOperation,
Expand Down Expand Up @@ -591,10 +589,16 @@ export class Collection<TSchema extends Document = Document> {
* @param options - Optional settings for the command
*/
async options(options?: OperationOptions): Promise<Document> {
return await executeOperation(
this.client,
new OptionsOperation(this as TODO_NODE_3286, resolveOptions(this, options))
);
options = resolveOptions(this, options);
const [collection] = await this.s.db
.listCollections({ name: this.collectionName }, { ...options, nameOnly: false })
.toArray();

if (collection == null || collection.options == null) {
throw new MongoAPIError(`collection ${this.namespace} not found`);
}

return collection.options;
}

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

/**
Expand Down
14 changes: 9 additions & 5 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { MongoInvalidArgumentError } from './error';
import type { MongoClient, PkFactory } from './mongo_client';
import type { Abortable, TODO_NODE_3286 } from './mongo_types';
import type { AggregateOptions } from './operations/aggregate';
import { CollectionsOperation } from './operations/collections';
import {
CreateCollectionOperation,
type CreateCollectionOptions
Expand Down Expand Up @@ -435,10 +434,15 @@ export class Db {
* @param options - Optional settings for the command
*/
async collections(options?: ListCollectionsOptions): Promise<Collection[]> {
return await executeOperation(
this.client,
new CollectionsOperation(this, resolveOptions(this, options))
);
options = resolveOptions(this, options);
const collections = await this.listCollections({}, { ...options, nameOnly: true }).toArray();

return collections
.filter(
// Filter collections removing any illegal ones
({ name }) => !name.includes('$')
)
.map(({ name }) => new Collection(this, name, this.s.options));
}

/**
Expand Down
47 changes: 0 additions & 47 deletions src/operations/collections.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/operations/is_capped.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/operations/options_operation.ts

This file was deleted.

15 changes: 0 additions & 15 deletions test/integration/crud/abstract_operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ describe('abstract operation', function () {
subclassType: mongodb.AggregateOperation,
correctCommandName: 'aggregate'
},
{
subclassCreator: () => new mongodb.CollectionsOperation(db, {}),
subclassType: mongodb.CollectionsOperation,
correctCommandName: 'listCollections'
},
{
subclassCreator: () => new mongodb.CountOperation(collection.fullNamespace, { a: 1 }, {}),
subclassType: mongodb.CountOperation,
Expand Down Expand Up @@ -155,11 +150,6 @@ describe('abstract operation', function () {
subclassType: mongodb.InsertOneOperation,
correctCommandName: 'insert'
},
{
subclassCreator: () => new mongodb.IsCappedOperation(collection, {}),
subclassType: mongodb.IsCappedOperation,
correctCommandName: 'listCollections'
},
{
subclassCreator: () =>
new mongodb.KillCursorsOperation(
Expand All @@ -181,11 +171,6 @@ describe('abstract operation', function () {
subclassType: mongodb.ListDatabasesOperation,
correctCommandName: 'listDatabases'
},
{
subclassCreator: () => new mongodb.OptionsOperation(collection, {}),
subclassType: mongodb.OptionsOperation,
correctCommandName: 'listCollections'
},
{
subclassCreator: () => new mongodb.ProfilingLevelOperation(db, {}),
subclassType: mongodb.ProfilingLevelOperation,
Expand Down
3 changes: 0 additions & 3 deletions test/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export * from '../src/operations/aggregate';
export * from '../src/operations/client_bulk_write/command_builder';
export * from '../src/operations/client_bulk_write/common';
export * from '../src/operations/client_bulk_write/results_merger';
export * from '../src/operations/collections';
export * from '../src/operations/command';
export * from '../src/operations/count';
export * from '../src/operations/create_collection';
Expand All @@ -180,12 +179,10 @@ export * from '../src/operations/find_and_modify';
export * from '../src/operations/get_more';
export * from '../src/operations/indexes';
export * from '../src/operations/insert';
export * from '../src/operations/is_capped';
export * from '../src/operations/kill_cursors';
export * from '../src/operations/list_collections';
export * from '../src/operations/list_databases';
export * from '../src/operations/operation';
export * from '../src/operations/options_operation';
export * from '../src/operations/profiling_level';
export * from '../src/operations/remove_user';
export * from '../src/operations/rename';
Expand Down