A remote collection of documents in a MongoDB database.

Type Parameters

Constructors

Properties

databaseName: string
serviceName: string

Accessors

  • get name(): string
  • The name of the collection.

    Returns string

Methods

  • Runs an aggregation framework pipeline against this collection.

    Parameters

    Returns Promise<unknown>

    A promise that resolves to the aggregation result.

  • 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

    • Optional filter: Filter

      An optional filter applied to narrow down the results.

    • Optional options: CountOptions

      Additional options to apply.

    Returns Promise<number>

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

  • Deletes multiple documents.

    Parameters

    • Optional filter: Filter

      A filter applied to narrow down the result. If omitted, it defaults to {} which deletes all documents in the collection.

    Returns Promise<DeleteResult>

    A promise that resolves to an object containing the number of deleted documents (deletedCount).

  • Deletes a single matching document from the collection.

    Parameters

    • Optional filter: Filter

      A filter applied to narrow down the result.

    Returns Promise<DeleteResult>

    A promise that resolves to an object containing the number of deleted documents (deletedCount).

  • Finds the documents which match the provided query.

    Parameters

    • Optional filter: Filter

      An optional filter applied to narrow down the results.

    • Optional options: FindOptions

      Additional options to apply.

    Returns Promise<T[]>

    A promise that resolves to the found documents.

  • Finds a document which matches the provided filter.

    Parameters

    • Optional filter: Filter

      A filter applied to narrow down the result.

    • Optional options: FindOneOptions

      Additional options to apply.

    Returns Promise<null | T>

    A promise that resolves to the found document.

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

    Parameters

    • Optional filter: Filter

      A filter applied to narrow down the result.

    • Optional 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.

    • Optional 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

    • filter: Filter

      A filter applied to narrow down the result.

    • update: Update

      The new values for the document.

    • Optional options: FindOneAndModifyOptions

      Additional options to apply.

    Returns Promise<null | T>

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

  • Inserts an array of documents into the collection. If any values are missing identifiers, they will be generated by the server.

    Parameters

    • documents: NewDocument<T>[]

      The array of documents to insert.

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

    A promise that resolves to an object containing an array of IDs inserted (insertedIds).

  • Inserts a single document into the collection. Note: If the document is missing an _id, one will be generated for it by the server.

    Parameters

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

    A promise that resolves an object containing the inserted object ID (insertedId).

  • 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.

    • Optional 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.

    • Optional 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