Uname: Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
Software: LiteSpeed
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.213.251.212
Your Ip: 3.15.5.176
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : collections.ts
import { Collection } from '../collection';
import type { Db } from '../db';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { AbstractOperation, type OperationOptions } from './operation';

export interface CollectionsOptions extends OperationOptions {
  nameOnly?: boolean;
}

/** @internal */
export class CollectionsOperation extends AbstractOperation<Collection[]> {
  override options: CollectionsOptions;
  db: Db;

  constructor(db: Db, options: CollectionsOptions) {
    super(options);
    this.options = options;
    this.db = db;
  }

  override get commandName() {
    return 'listCollections' as const;
  }

  override async execute(
    server: Server,
    session: ClientSession | undefined
  ): Promise<Collection[]> {
    // Let's get the collection names
    const documents = await this.db
      .listCollections(
        {},
        { ...this.options, nameOnly: true, readPreference: this.readPreference, session }
      )
      .toArray();
    const collections: Collection[] = [];
    for (const { name } of documents) {
      if (!name.includes('$')) {
        // Filter collections removing any illegal ones
        collections.push(new Collection(this.db, name, this.db.s.options));
      }
    }
    // Return the collection objects
    return collections;
  }
}
© 2025 GrazzMean-Shell