Class MongoDBCollection<T>

A remote collection of documents in a MongoDB database.

Type Parameters

Properties

databaseName: string
serviceName: string

Accessors

Methods

  • Counts the number of documents in this collection matching the provided filter.

    Note: When calling this without a filter, you may receive inaccurate document counts as it returns results based on the collection's metadata, which may result in an approximate count. In particular:

    • On a sharded cluster, the resulting count will not correctly filter out orphaned documents.
    • After an unclean shutdown or file copy based initial sync, the count may be incorrect.

    Parameters

    • filter: Filter = {}

      An optional filter applied to narrow down the results.

    • options: CountOptions = {}

      Additional options to apply.

    Returns Promise<number>

    A promise that resolves to the number of documents matching the filter.

  • Finds a document which matches the provided filter and deletes it

    Parameters

    • filter: Filter = {}

      A filter applied to narrow down the result.

    • options: FindOneOptions = {}

      Additional options to apply.

    Returns Promise<null | T>

    A promise that resolves to the found document before deletion.

  • Finds a document which matches the provided filter and replaces it with a new document.

    Parameters

    • filter: Filter

      A filter applied to narrow down the result.

    • replacement: unknown

      The new replacing document.

    • options: FindOneAndModifyOptions = {}

      Additional options to apply.

    Returns Promise<null | T>

    A promise that resolves to the found document found before replacement.

  • Finds a document which matches the provided query and performs the desired update to individual fields.

    Parameters

    Returns Promise<null | T>

    A promise that resolves to the found document before applying the update.

  • Updates multiple documents matching the provided filter in this collection.

    Parameters

    • filter: Filter

      A filter applied to narrow down the result.

    • update: Update

      The new values for the documents.

    • options: UpdateOptions = {}

      Additional options to apply.

    Returns Promise<UpdateResult<T["_id"]>>

    A promise that resolves to an object containing:

    {
    matchedCount: number;
    modifiedCount: number;
    upsertedId: IdType | undefined;
    }
  • Updates a single document matching the provided filter in this collection.

    Parameters

    • filter: Filter

      A filter applied to narrow down the result.

    • update: Update

      The new values for the document.

    • options: UpdateOptions = {}

      Additional options to apply.

    Returns Promise<UpdateResult<T["_id"]>>

    A promise that resolves to an object containing:

    {
    matchedCount: number;
    modifiedCount: number;
    upsertedId: IdType | undefined;
    }

Generated using TypeDoc