Options
All
  • Public
  • Public/Protected
  • All
Menu

mongodb

Index

References

Namespaces

Classes Error

Classes Event

Classes Other

Interfaces

Type aliases

Variables

References

Re-exports BSONRegExp
Re-exports BSONSymbol
Re-exports BSONType
Re-exports Binary
Re-exports Code
Re-exports DBRef
Re-exports Decimal128
Re-exports Document
Re-exports Double
Re-exports Int32
Re-exports Long
Re-exports MaxKey
Re-exports MinKey
Re-exports ObjectId
Re-exports Timestamp
Re-exports deserialize
Re-exports serialize

Type aliases

AbstractCursorEvents: { close: any }

Type declaration

AcceptedFields<TSchema, FieldType, AssignableType>: { readonly [ key in KeysOfAType<TSchema, FieldType>]?: AssignableType }

Type parameters

  • TSchema

  • FieldType

  • AssignableType

AddToSetOperators<Type>: { $each?: Flatten<Type>[] }

Type parameters

  • Type

Type declaration

AlternativeType<T>: T extends ReadonlyArray<infer U> ? T | RegExpOrString<U> : RegExpOrString<T>

It is possible to search using alternative types in mongodb e.g. string types can be searched using a regex in mongo array types can be searched using their element type

Type parameters

  • T

AnyBulkWriteOperation<TSchema>: { insertOne: InsertOneModel<TSchema> } | { replaceOne: ReplaceOneModel<TSchema> } | { updateOne: UpdateOneModel<TSchema> } | { updateMany: UpdateManyModel<TSchema> } | { deleteOne: DeleteOneModel<TSchema> } | { deleteMany: DeleteManyModel<TSchema> }

Type parameters

AnyError: MongoError | Error
ArrayElement<Type>: Type extends ReadonlyArray<infer Item> ? Item : never

Type parameters

  • Type

ArrayOperator<Type>: { $each?: Flatten<Type>[]; $position?: number; $slice?: number; $sort?: Sort }

Type parameters

  • Type

Type declaration

  • Optional $each?: Flatten<Type>[]
  • Optional $position?: number
  • Optional $slice?: number
  • Optional $sort?: Sort
AuthMechanism: typeof AuthMechanism[keyof typeof AuthMechanism]
AutoEncryptionLoggerLevel: typeof AutoEncryptionLoggerLevel[keyof typeof AutoEncryptionLoggerLevel]
BSONTypeAlias: keyof typeof BSON.BSONType
BatchType: typeof BatchType[keyof typeof BatchType]
BitwiseFilter: number | Binary | ReadonlyArray<number>
Callback<T>: (error?: AnyError, result?: T) => void

Type parameters

  • T = any

Type declaration

    • MongoDB Driver style callback

      Parameters

      • Optional error: AnyError
      • Optional result: T

      Returns void

Type parameters

ChangeStreamEvents<TSchema, TChange>: { change: any; end: any; error: any; init: any; more: any; response: any; resumeTokenChanged: any } & AbstractCursorEvents

Type parameters

ClientSessionEvents: { ended: any }

Type declaration

CommonEvents: "newListener" | "removeListener"
Compressor: typeof Compressor[CompressorName]
CompressorName: keyof typeof Compressor

Type parameters

  • T

ConnectionEvents: { close: any; clusterTimeReceived: any; commandFailed: any; commandStarted: any; commandSucceeded: any; message: any; pinned: any; unpinned: any }

Type declaration

ConnectionPoolEvents: { connectionCheckOutFailed: any; connectionCheckOutStarted: any; connectionCheckedIn: any; connectionCheckedOut: any; connectionClosed: any; connectionCreated: any; connectionPoolCleared: any; connectionPoolClosed: any; connectionPoolCreated: any; connectionPoolReady: any; connectionReady: any } & Omit<ConnectionEvents, "close" | "message">
CursorFlag: typeof CURSOR_FLAGS[number]
DistinctOptions: CommandOperationOptions
DropDatabaseOptions: CommandOperationOptions
DropIndexesOptions: CommandOperationOptions
EnhancedOmit<TRecordOrUnion, KeyUnion>: string extends keyof TRecordOrUnion ? TRecordOrUnion : TRecordOrUnion extends any ? Pick<TRecordOrUnion, Exclude<keyof TRecordOrUnion, KeyUnion>> : never

TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public

Type parameters

  • TRecordOrUnion

  • KeyUnion

EventEmitterWithState: { }

Type declaration

    EventsDescription: Record<string, GenericListener>

    Event description type

    ExplainVerbosity: string
    ExplainVerbosityLike: ExplainVerbosity | boolean

    For backwards compatibility, true is interpreted as "allPlansExecution" and false as "queryPlanner". Prior to server version 3.6, aggregate() ignores the verbosity parameter and executes in "queryPlanner".

    Filter<TSchema>: { [ P in keyof WithId<TSchema>]?: Condition<WithId<TSchema>[P]> } & RootFilterOperators<WithId<TSchema>>

    A MongoDB filter can be some portion of the schema or a set of operators @public

    Type parameters

    • TSchema

    FilterOperations<T>: T extends Record<string, any> ? { [ key in keyof T]?: FilterOperators<T[key]> } : FilterOperators<T>

    Type parameters

    • T

    Flatten<Type>: Type extends ReadonlyArray<infer Item> ? Item : Type

    Type parameters

    • Type

    GSSAPICanonicalizationValue: typeof GSSAPICanonicalizationValue[keyof typeof GSSAPICanonicalizationValue]
    GenericListener: (...args: any[]) => void

    Type declaration

      • (...args: any[]): void
      • Parameters

        • Rest ...args: any[]

        Returns void

    GridFSBucketEvents: { index: any }

    Type declaration

    Hint: string | Document
    IndexDirection: -1 | 1 | "2d" | "2dsphere" | "text" | "geoHaystack" | "hashed" | number
    IndexSpecification: OneOrMore<string | [string, IndexDirection] | {} | Map<string, IndexDirection>>
    InferIdType<TSchema>: TSchema extends { _id: infer IdType } ? Record<any, never> extends IdType ? never : IdType : TSchema extends { _id?: infer IdType } ? unknown extends IdType ? ObjectId : IdType : ObjectId

    Given an object shaped type, return the type of the _id field or default to ObjectId @public

    Type parameters

    • TSchema

    IntegerType: number | Int32 | Long | bigint
    IsAny<Type, ResultIfAny, ResultIfNotAny>: true extends false & Type ? ResultIfAny : ResultIfNotAny

    Type parameters

    • Type

    • ResultIfAny

    • ResultIfNotAny

    Join<T, D>: T extends [] ? "" : T extends [string | number] ? `${T[0]}` : T extends [string | number, ...infer R] ? `${T[0]}${D}${Join<R, D>}` : string

    Type parameters

    • T: unknown[]

    • D: string

    KeysOfAType<TSchema, Type>: { [ key in keyof TSchema]: NonNullable<TSchema[key]> extends Type ? key : never }[keyof TSchema]

    Type parameters

    • TSchema

    • Type

    KeysOfOtherType<TSchema, Type>: { [ key in keyof TSchema]: NonNullable<TSchema[key]> extends Type ? never : key }[keyof TSchema]

    Type parameters

    • TSchema

    • Type

    MatchKeysAndValues<TSchema>: Readonly<Partial<TSchema>> & Record<string, any>

    Type parameters

    • TSchema

    MongoClientEvents: Pick<TopologyEvents, typeof MONGO_CLIENT_EVENTS[number]> & { open: any }
    MongoErrorLabel: typeof MongoErrorLabel[keyof typeof MongoErrorLabel]
    MonitorEvents: { close: any; resetConnectionPool: any; resetServer: any; serverHeartbeatFailed: any; serverHeartbeatStarted: any; serverHeartbeatSucceeded: any } & EventEmitterWithState
    NestedPaths<Type, Depth>: Depth["length"] extends 8 ? [] : Type extends string | number | bigint | boolean | Date | RegExp | Buffer | Uint8Array | ((...args: any[]) => any) | { _bsontype: string } ? [] : Type extends ReadonlyArray<infer ArrayType> ? [] | [number, ...NestedPaths<ArrayType, [...Depth, 1]>] : Type extends Map<string, any> ? [string] : Type extends object ? { [ Key in Extract<keyof Type, string>]: Type[Key] extends Type ? [Key] : Type extends Type[Key] ? [Key] : Type[Key] extends ReadonlyArray<infer ArrayType> ? Type extends ArrayType ? [Key] : ArrayType extends Type ? [Key] : [Key, ...NestedPaths<Type[Key], [...Depth, 1]>] : [Key, ...NestedPaths<Type[Key], [...Depth, 1]>] | [Key] }[Extract<keyof Type, string>] : []
    remarks

    Through testing we determined that a depth of 8 is safe for the typescript compiler and provides reasonable compilation times. This number is otherwise not special and should be changed if issues are found with this level of checking. Beyond this depth any helpers that make use of NestedPaths should devolve to not asserting any type safety on the input.

    Type parameters

    • Type

    • Depth: number[]

    NestedPathsOfType<TSchema, Type>: KeysOfAType<{ [ Property in Join<NestedPaths<TSchema, []>, ".">]: PropertyType<TSchema, Property> }, Type>

    Type parameters

    • TSchema

    • Type

    NonObjectIdLikeDocument: { [ key in keyof ObjectIdLike]?: never } & Document
    NotAcceptedFields<TSchema, FieldType>: { readonly [ key in KeysOfOtherType<TSchema, FieldType>]?: never }

    It avoids using fields with not acceptable types @public

    Type parameters

    • TSchema

    • FieldType

    NumericType: IntegerType | Decimal128 | Double
    OneOrMore<T>: T | ReadonlyArray<T>

    Type parameters

    • T

    OnlyFieldsOfType<TSchema, FieldType, AssignableType>: IsAny<TSchema[keyof TSchema], Record<string, FieldType>, AcceptedFields<TSchema, FieldType, AssignableType> & NotAcceptedFields<TSchema, FieldType> & Record<string, AssignableType>>

    Type parameters

    • TSchema

    • FieldType = any

    • AssignableType = FieldType

    OperationTime: Timestamp

    Represents a specific point in time on a server. Can be retrieved by using db.command()

    see

    https://docs.mongodb.com/manual/reference/method/db.runCommand/#response

    OptionalId<TSchema>: EnhancedOmit<TSchema, "_id"> & { _id?: InferIdType<TSchema> }

    Add an optional _id field to an object shaped type

    Type parameters

    • TSchema

    OptionalUnlessRequiredId<TSchema>: TSchema extends { _id: any } ? TSchema : OptionalId<TSchema>

    Adds an optional _id field to an object shaped type, unless the _id field is required on that type. In the case _id is required, this method continues to require_id.

    privateremarks

    ObjectId extends TSchema['_id'] is a confusing ordering at first glance. Rather than ask TSchema['_id'] extends ObjectId which translated to "Is the _id property ObjectId?" we instead ask "Does ObjectId look like (have the same shape) as the _id?"

    Type parameters

    • TSchema

    ProfilingLevel: typeof ProfilingLevel[keyof typeof ProfilingLevel]
    ProfilingLevelOptions: CommandOperationOptions
    PropertyType<Type, Property>: string extends Property ? unknown : Property extends keyof Type ? Type[Property] : Property extends `${number}` ? Type extends ReadonlyArray<infer ArrayType> ? ArrayType : unknown : Property extends `${infer Key}.${infer Rest}` ? Key extends `${number}` ? Type extends ReadonlyArray<infer ArrayType> ? PropertyType<ArrayType, Rest> : unknown : Key extends keyof Type ? Type[Key] extends Map<string, infer MapType> ? MapType : PropertyType<Type[Key], Rest> : unknown : unknown

    Type parameters

    • Type

    • Property: string

    PullAllOperator<TSchema>: ({ readonly [ key in KeysOfAType<TSchema, ReadonlyArray<any>>]?: TSchema[key] } & NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {}

    Type parameters

    • TSchema

    PullOperator<TSchema>: ({ readonly [ key in KeysOfAType<TSchema, ReadonlyArray<any>>]?: Partial<Flatten<TSchema[key]>> | FilterOperations<Flatten<TSchema[key]>> } & NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {}

    Type parameters

    • TSchema

    PushOperator<TSchema>: ({ readonly [ key in KeysOfAType<TSchema, ReadonlyArray<any>>]?: Flatten<TSchema[key]> | ArrayOperator<Flatten<TSchema[key]>[]> } & NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {}

    Type parameters

    • TSchema

    ReadConcernLevel: typeof ReadConcernLevel[keyof typeof ReadConcernLevel]
    ReadConcernLike: ReadConcern | { level: ReadConcernLevel } | ReadConcernLevel
    ReadPreferenceLike: ReadPreference | ReadPreferenceMode
    ReadPreferenceMode: typeof ReadPreferenceMode[keyof typeof ReadPreferenceMode]
    RegExpOrString<T>: T extends string ? BSONRegExp | RegExp | T : T

    Type parameters

    • T

    RemoveUserOptions: CommandOperationOptions
    ResumeToken: unknown

    Represents the logical starting point for a new ChangeStream or resuming a ChangeStream on the server.

    see

    https://www.mongodb.com/docs/manual/changeStreams/#std-label-change-stream-resume

    ReturnDocument: typeof ReturnDocument[keyof typeof ReturnDocument]
    RunCommandOptions: CommandOperationOptions
    SchemaMember<T, V>: { [ P in keyof T]?: V } | {}

    Type parameters

    • T

    • V

    ServerApiVersion: typeof ServerApiVersion[keyof typeof ServerApiVersion]
    ServerEvents: { closed: any; connect: any; descriptionReceived: any; ended: any; serverHeartbeatFailed: any; serverHeartbeatStarted: any; serverHeartbeatSucceeded: any } & ConnectionPoolEvents & EventEmitterWithState
    ServerSessionId: { id: Binary }

    Type declaration

    ServerType: typeof ServerType[keyof typeof ServerType]
    SetFields<TSchema>: ({ readonly [ key in KeysOfAType<TSchema, ReadonlyArray<any> | undefined>]?: OptionalId<Flatten<TSchema[key]>> | AddToSetOperators<OptionalId<Flatten<TSchema[key]>>[]> } & NotAcceptedFields<TSchema, ReadonlyArray<any> | undefined>) & {}

    Type parameters

    • TSchema

    SetProfilingLevelOptions: CommandOperationOptions
    Sort: string | Exclude<SortDirection, { $meta: string }> | string[] | {} | Map<string, SortDirection> | [string, SortDirection][] | [string, SortDirection]
    SortDirection: 1 | -1 | "asc" | "desc" | "ascending" | "descending" | { $meta: string }
    Stream: Socket | TLSSocket
    StrictFilter<TSchema>: Partial<TSchema> | ({ [ Property in Join<NestedPaths<WithId<TSchema>, []>, ".">]?: Condition<PropertyType<WithId<TSchema>, Property>> } & RootFilterOperators<WithId<TSchema>>)
    experimental

    Type parameters

    • TSchema

    StrictMatchKeysAndValues<TSchema>: Readonly<{ [ Property in Join<NestedPaths<TSchema, []>, ".">]?: PropertyType<TSchema, Property> } & { [ Property in `${NestedPathsOfType<TSchema, any[]>}.$${`[${string}]` | ""}`]?: ArrayElement<PropertyType<TSchema, Property extends `${infer Key}.$${string}` ? Key : never>> } & { [ Property in `${NestedPathsOfType<TSchema, Record<string, any>[]>}.$${`[${string}]` | ""}.${string}`]?: any } & Document>
    experimental

    Type parameters

    • TSchema

    StrictUpdateFilter<TSchema>: { $addToSet?: SetFields<TSchema>; $bit?: OnlyFieldsOfType<TSchema, NumericType | undefined, { and: IntegerType } | { or: IntegerType } | { xor: IntegerType }>; $currentDate?: OnlyFieldsOfType<TSchema, Date | Timestamp, true | { $type: "date" | "timestamp" }>; $inc?: OnlyFieldsOfType<TSchema, NumericType | undefined>; $max?: StrictMatchKeysAndValues<TSchema>; $min?: StrictMatchKeysAndValues<TSchema>; $mul?: OnlyFieldsOfType<TSchema, NumericType | undefined>; $pop?: OnlyFieldsOfType<TSchema, ReadonlyArray<any>, 1 | -1>; $pull?: PullOperator<TSchema>; $pullAll?: PullAllOperator<TSchema>; $push?: PushOperator<TSchema>; $rename?: Record<string, string>; $set?: StrictMatchKeysAndValues<TSchema>; $setOnInsert?: StrictMatchKeysAndValues<TSchema>; $unset?: OnlyFieldsOfType<TSchema, any, "" | true | 1> } & Document
    experimental

    Type parameters

    • TSchema

    SupportedSocketOptions: Pick<TcpNetConnectOpts, typeof LEGAL_TCP_SOCKET_OPTIONS[number]>
    SupportedTLSConnectionOptions: Pick<TLSConnectionOptions, Extract<keyof TLSConnectionOptions, typeof LEGAL_TLS_SOCKET_OPTIONS[number]>>
    SupportedTLSSocketOptions: Pick<TLSSocketOptions, Extract<keyof TLSSocketOptions, typeof LEGAL_TLS_SOCKET_OPTIONS[number]>>
    TagSet: {}

    Type declaration

    • [key: string]: string
    TopologyEvents: { close: any; connect: any; error: any; serverClosed: any; serverDescriptionChanged: any; serverOpening: any; timeout: any; topologyClosed: any; topologyDescriptionChanged: any; topologyOpening: any } & Omit<ServerEvents, "connect"> & ConnectionPoolEvents & ConnectionEvents & EventEmitterWithState
    TopologyType: typeof TopologyType[keyof typeof TopologyType]
    UpdateFilter<TSchema>: { $addToSet?: SetFields<TSchema>; $bit?: OnlyFieldsOfType<TSchema, NumericType | undefined, { and: IntegerType } | { or: IntegerType } | { xor: IntegerType }>; $currentDate?: OnlyFieldsOfType<TSchema, Date | Timestamp, true | { $type: "date" | "timestamp" }>; $inc?: OnlyFieldsOfType<TSchema, NumericType | undefined>; $max?: MatchKeysAndValues<TSchema>; $min?: MatchKeysAndValues<TSchema>; $mul?: OnlyFieldsOfType<TSchema, NumericType | undefined>; $pop?: OnlyFieldsOfType<TSchema, ReadonlyArray<any>, 1 | -1>; $pull?: PullOperator<TSchema>; $pullAll?: PullAllOperator<TSchema>; $push?: PushOperator<TSchema>; $rename?: Record<string, string>; $set?: MatchKeysAndValues<TSchema>; $setOnInsert?: MatchKeysAndValues<TSchema>; $unset?: OnlyFieldsOfType<TSchema, any, "" | true | 1> } & Document

    Type parameters

    • TSchema

    W: number | "majority"
    WithId<TSchema>: EnhancedOmit<TSchema, "_id"> & { _id: InferIdType<TSchema> }

    Add an _id field to an object shaped type @public

    Type parameters

    • TSchema

    WithSessionCallback: (session: ClientSession) => Promise<any>

    Type declaration

    WithTransactionCallback<T>: (session: ClientSession) => Promise<T>

    Type parameters

    • T = void

    Type declaration

    WithoutId<TSchema>: Omit<TSchema, "_id">

    Remove the _id field from an object shaped type @public

    Type parameters

    • TSchema

    Variables

    AuthMechanism: Readonly<{ MONGODB_AWS: "MONGODB-AWS"; MONGODB_CR: "MONGODB-CR"; MONGODB_DEFAULT: "DEFAULT"; MONGODB_GSSAPI: "GSSAPI"; MONGODB_OIDC: "MONGODB-OIDC"; MONGODB_PLAIN: "PLAIN"; MONGODB_SCRAM_SHA1: "SCRAM-SHA-1"; MONGODB_SCRAM_SHA256: "SCRAM-SHA-256"; MONGODB_X509: "MONGODB-X509" }> = ...
    AutoEncryptionLoggerLevel: Readonly<{ Error: 1; FatalError: 0; Info: 3; Trace: 4; Warning: 2 }> = ...
    BatchType: Readonly<{ DELETE: 3; INSERT: 1; UPDATE: 2 }> = ...
    CURSOR_FLAGS: readonly ["tailable", "oplogReplay", "noCursorTimeout", "awaitData", "exhaust", "partial"] = ...
    Compressor: Readonly<{ none: 0; snappy: 1; zlib: 2; zstd: 3 }> = ...
    ExplainVerbosity: Readonly<{ allPlansExecution: "allPlansExecution"; executionStats: "executionStats"; queryPlanner: "queryPlanner"; queryPlannerExtended: "queryPlannerExtended" }> = ...
    GSSAPICanonicalizationValue: Readonly<{ forward: "forward"; forwardAndReverse: "forwardAndReverse"; none: "none"; off: false; on: true }> = ...
    LEGAL_TCP_SOCKET_OPTIONS: readonly ["family", "hints", "localAddress", "localPort", "lookup"] = ...
    LEGAL_TLS_SOCKET_OPTIONS: readonly ["ALPNProtocols", "ca", "cert", "checkServerIdentity", "ciphers", "crl", "ecdhCurve", "key", "minDHSize", "passphrase", "pfx", "rejectUnauthorized", "secureContext", "secureProtocol", "servername", "session"] = ...
    MONGO_CLIENT_EVENTS: readonly ["connectionPoolCreated", "connectionPoolReady", "connectionPoolCleared", "connectionPoolClosed", "connectionCreated", "connectionReady", "connectionClosed", "connectionCheckOutStarted", "connectionCheckOutFailed", "connectionCheckedOut", "connectionCheckedIn", "commandStarted", "commandSucceeded", "commandFailed", "serverOpening", "serverClosed", "serverDescriptionChanged", "topologyOpening", "topologyClosed", "topologyDescriptionChanged", "error", "timeout", "close", "serverHeartbeatStarted", "serverHeartbeatSucceeded", "serverHeartbeatFailed"] = ...
    MongoErrorLabel: Readonly<{ HandshakeError: "HandshakeError"; InterruptInUseConnections: "InterruptInUseConnections"; NoWritesPerformed: "NoWritesPerformed"; ResetPool: "ResetPool"; ResumableChangeStreamError: "ResumableChangeStreamError"; RetryableWriteError: "RetryableWriteError"; TransientTransactionError: "TransientTransactionError"; UnknownTransactionCommitResult: "UnknownTransactionCommitResult" }> = ...
    ProfilingLevel: Readonly<{ all: "all"; off: "off"; slowOnly: "slow_only" }> = ...
    ReadConcernLevel: Readonly<{ available: "available"; linearizable: "linearizable"; local: "local"; majority: "majority"; snapshot: "snapshot" }> = ...
    ReadPreferenceMode: Readonly<{ nearest: "nearest"; primary: "primary"; primaryPreferred: "primaryPreferred"; secondary: "secondary"; secondaryPreferred: "secondaryPreferred" }> = ...
    ReturnDocument: Readonly<{ AFTER: "after"; BEFORE: "before" }> = ...
    ServerApiVersion: Readonly<{ v1: "1" }> = ...
    ServerType: Readonly<{ LoadBalancer: "LoadBalancer"; Mongos: "Mongos"; PossiblePrimary: "PossiblePrimary"; RSArbiter: "RSArbiter"; RSGhost: "RSGhost"; RSOther: "RSOther"; RSPrimary: "RSPrimary"; RSSecondary: "RSSecondary"; Standalone: "Standalone"; Unknown: "Unknown" }> = ...

    An enumeration of server types we know about

    TopologyType: Readonly<{ LoadBalanced: "LoadBalanced"; ReplicaSetNoPrimary: "ReplicaSetNoPrimary"; ReplicaSetWithPrimary: "ReplicaSetWithPrimary"; Sharded: "Sharded"; Single: "Single"; Unknown: "Unknown" }> = ...

    An enumeration of topology types we know about

    Generated using TypeDoc