Class Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

Type Parameters

  • ResultType

  • DocType

  • THelpers = {}

  • RawDocType = DocType

  • QueryOp = "find"

Hierarchy

  • Query

Implements

Constructors

  • Type Parameters

    • ResultType

    • DocType

    • THelpers = {}

    • RawDocType = DocType

    • QueryOp = "find"

    Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

Properties

[toStringTag]: string
_mongooseOptions: MongooseQueryOptions<DocType>
catch: (<TResult>(onrejected?) => Promise<ResultType | TResult>)

Type declaration

    • <TResult>(onrejected?): Promise<ResultType | TResult>
    • Executes the query returning a Promise which will be resolved with either the doc(s) or rejected with the error. Like .then(), but only takes a rejection handler.

      Type Parameters

      • TResult = never

      Parameters

      • Optional onrejected: ((reason) => TResult | PromiseLike<TResult>)
        Optional
          • (reason): TResult | PromiseLike<TResult>
          • Parameters

            • reason: any

            Returns TResult | PromiseLike<TResult>

      Returns Promise<ResultType | TResult>

finally: ((onfinally?) => Promise<ResultType>)

Type declaration

    • (onfinally?): Promise<ResultType>
    • Executes the query returning a Promise which will be resolved with .finally() chained.

      Parameters

      • Optional onfinally: (() => void)
        Optional
          • (): void
          • Returns void

      Returns Promise<ResultType>

model: mongoose.Model<any, {}, {}, {}, any, any>

The model this query was created from

Type declaration

    Type declaration

      Type declaration

        then: (<TResult1, TResult2>(onfulfilled?, onrejected?) => Promise<TResult1 | TResult2>)

        Type declaration

          • <TResult1, TResult2>(onfulfilled?, onrejected?): Promise<TResult1 | TResult2>
          • Executes the query returning a Promise which will be resolved with either the doc(s) or rejected with the error.

            Type Parameters

            • TResult1 = ResultType

            • TResult2 = never

            Parameters

            • Optional onfulfilled: ((value) => TResult1 | PromiseLike<TResult1>)
              Optional
                • (value): TResult1 | PromiseLike<TResult1>
                • Parameters

                  • value: ResultType

                  Returns TResult1 | PromiseLike<TResult1>

            • Optional onrejected: ((reason) => TResult2 | PromiseLike<TResult2>)
              Optional
                • (reason): TResult2 | PromiseLike<TResult2>
                • Parameters

                  • reason: any

                  Returns TResult2 | PromiseLike<TResult2>

            Returns Promise<TResult1 | TResult2>

        Methods

        • Parameters

          • argument: string | Function

          Returns QueryWithHelpers<DocType[], DocType, THelpers, RawDocType, QueryOp>

        • Returns a wrapper around a mongodb driver cursor. A QueryCursor exposes a Streams3 interface, as well as a .next() function. This is equivalent to calling .cursor() with no arguments.

          Returns AsyncIterableIterator<DocType>

        • Specifies an $all query condition. When called with one argument, the most recent path passed to where() is used.

          Parameters

          • path: string
          • val: any[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: any[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets the allowDiskUse option for the query (ignored for < 4.4.0)

          Parameters

          • value: boolean

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies arguments for an $and condition.

          Parameters

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies the batchSize option.

          Parameters

          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a $box condition

          Parameters

          • lower: number[]
          • upper: number[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Casts this query to the schema of model.

          Parameters

          • Optional model: mongoose.Model<any, THelpers, {}, {}, any, any>

            the model to cast to. If not set, defaults to this.model

            Optional
          • Optional obj: any

            If not set, defaults to this query's conditions

            Optional

          Returns any

          the casted obj

        • Specifies a $center or $centerSphere condition.

          Parameters

          • path: string
          • area: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • area: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Make a copy of this query so you can re-execute it.

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Adds a collation to this op (MongoDB 3.4 and up)

          Parameters

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies the comment option.

          Parameters

          • val: string

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies this query as a count query.

          Parameters

          Returns QueryWithHelpers<number, DocType, THelpers, RawDocType, "count">

        • Specifies this query as a countDocuments query.

          Parameters

          Returns QueryWithHelpers<number, DocType, THelpers, RawDocType, "countDocuments">

        • Declare and/or execute this query as a deleteMany() operation. Works like remove, except it deletes every document that matches filter in the collection, regardless of the value of single.

          Parameters

          Returns QueryWithHelpers<any, DocType, THelpers, RawDocType, "deleteMany">

        • Parameters

          Returns QueryWithHelpers<any, DocType, THelpers, RawDocType, "deleteMany">

        • Returns QueryWithHelpers<any, DocType, THelpers, RawDocType, "deleteMany">

        • Declare and/or execute this query as a deleteOne() operation. Works like remove, except it deletes at most one document regardless of the single option.

          Parameters

          Returns QueryWithHelpers<any, DocType, THelpers, RawDocType, "deleteOne">

        • Parameters

          Returns QueryWithHelpers<any, DocType, THelpers, RawDocType, "deleteOne">

        • Returns QueryWithHelpers<any, DocType, THelpers, RawDocType, "deleteOne">

        • Creates a distinct query: returns the distinct values of the given field that match filter.

          Type Parameters

          • ReturnType = any

          Parameters

          • field: string
          • Optional filter: FilterQuery<RawDocType>
            Optional

          Returns QueryWithHelpers<ReturnType[], DocType, THelpers, RawDocType, "distinct">

        • Specifies a $elemMatch query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies the complementary comparison value for paths specified with where()

          Parameters

          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Gets/sets the error flag on this query. If this flag is not null or undefined, the exec() promise will reject without executing.

          Returns NativeError

        • Parameters

          • val: NativeError

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Creates a estimatedDocumentCount query: counts the number of documents in the collection.

          Parameters

          Returns QueryWithHelpers<number, DocType, THelpers, RawDocType, "estimatedDocumentCount">

        • Executes the query

          Returns Promise<ResultType>

        • Specifies a $exists query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: boolean

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: boolean

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets the explain option, which makes this query return detailed execution stats instead of the actual query result. This method is useful for determining what index your queries use.

          Parameters

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Creates a find query: gets a list of documents that match filter.

          Parameters

          Returns QueryWithHelpers<DocType[], DocType, THelpers, RawDocType, "find">

        • Parameters

          Returns QueryWithHelpers<DocType[], DocType, THelpers, RawDocType, "find">

        • Parameters

          Returns QueryWithHelpers<DocType[], DocType, THelpers, RawDocType, "find">

        • Returns QueryWithHelpers<DocType[], DocType, THelpers, RawDocType, "find">

        • Declares the query a findById operation. When executed, returns the document with the given _id.

          Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOne">

        • Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOne">

        • Parameters

          • id: any

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOne">

        • Creates a findByIdAndDelete query, filtering by the given _id.

          Parameters

          Returns QueryWithHelpers<mongoose.ModifyResult<DocType>, DocType, THelpers, RawDocType, "findOneAndDelete">

        • Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOneAndDelete">

        • Creates a findOneAndUpdate query, filtering by the given _id.

          Parameters

          Returns QueryWithHelpers<any, DocType, THelpers, RawDocType, "findOneAndUpdate">

        • Parameters

          • id: any
          • update: UpdateQuery<RawDocType>
          • options: Object

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOneAndUpdate">

        • Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOneAndUpdate">

        • Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOneAndUpdate">

        • Declares the query a findOne operation. When executed, returns the first found document.

          Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOne">

        • Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOne">

        • Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOne">

        • Creates a findOneAndDelete query: atomically finds the given document, deletes it, and returns the document as it was before deletion.

          Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOneAndDelete">

        • Creates a findOneAndRemove query: atomically finds the given document and deletes it.

          Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOneAndRemove">

        • Creates a findOneAndUpdate query: atomically find the first document that matches filter and apply update.

          Parameters

          Returns QueryWithHelpers<mongoose.ModifyResult<DocType>, DocType, THelpers, RawDocType, "findOneAndUpdate">

        • Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOneAndUpdate">

        • Parameters

          Returns QueryWithHelpers<DocType, DocType, THelpers, RawDocType, "findOneAndUpdate">

        • Specifies a $geometry condition

          Parameters

          • object: {
                coordinates: any[];
                type: string;
            }
            • coordinates: any[]
            • type: string

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • For update operations, returns the value of a path in the update's $set. Useful for writing getters/setters that can work with both update operations and save().

          Parameters

          • path: string

          Returns any

        • Returns the current query filter (also known as conditions) as a POJO.

          Returns FilterQuery<RawDocType>

        • Gets a list of paths to be populated by this query

          Returns string[]

        • Returns the current query filter. Equivalent to getFilter().

          Returns FilterQuery<RawDocType>

        • Specifies a $gt query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a $gte query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets query hints.

          Parameters

          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies an $in query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: any[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Declares an intersects query for geometry().

          Parameters

          • Optional arg: any
            Optional

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Requests acknowledgement that this operation has been persisted to MongoDB's on-disk journal.

          Parameters

          • val: boolean

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets the lean option.

          Type Parameters

          Parameters

          • Optional val: any
            Optional

          Returns QueryWithHelpers<ResultType extends null
              ? LeanResultType
              : LeanResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies the maximum number of documents the query will return.

          Parameters

          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a $lt query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a $lte query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies an $maxDistance query condition. When called with one argument, the most recent path passed to where() is used.

          Parameters

          • path: string
          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets the maxTimeMS option. This will tell the MongoDB server to abort if the query or write op has been running for more than ms milliseconds.

          Parameters

          • ms: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Merges another Query or conditions object into this one.

          Parameters

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a $mod condition, filters documents for documents whose path property is a number that is equal to remainder modulo divisor.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: number[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Getter/setter around the current mongoose-specific options for this query Below are the current Mongoose-specific options.

          Parameters

          Returns MongooseQueryOptions<unknown>

        • Specifies a $ne query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a $near or $nearSphere condition

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: any

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies an $nin query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: any[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies arguments for an $nor condition.

          Parameters

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies arguments for an $or condition.

          Parameters

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Make this query throw an error if no documents match the given filter. This is handy for integrating with async/await, because orFail() saves you an extra if statement to check if no document was found.

          Parameters

          • Optional err: NativeError | (() => NativeError)
            Optional

          Returns QueryWithHelpers<NonNullable<ResultType>, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a $polygon condition

          Parameters

          • path: string
          • Rest ...coordinatePairs: number[][]
            Rest

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • Rest ...coordinatePairs: number[][]
            Rest

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Get/set the current projection (AKA fields). Pass null to remove the current projection.

          Parameters

          Returns ProjectionFields<DocType>

        • Parameters

          • fields: null

          Returns null

        • Returns ProjectionFields<DocType>

        • Determines the MongoDB nodes from which to read.

          Parameters

          • mode: string
          • Optional tags: any[]
            Optional

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets the readConcern option for the query.

          Parameters

          • level: string

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a $regex query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: RegExp

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: string | RegExp

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Declare and/or execute this query as a replaceOne() operation. Same as update(), except MongoDB will replace the existing document and will not accept any atomic operators ($set, etc.)

          Parameters

          Returns QueryWithHelpers<any, DocType, THelpers, RawDocType, "replaceOne">

        • Specifies which document fields to include or exclude (also known as the query "projection")

          Type Parameters

          • RawDocTypeOverride extends {
                [P in string | number | symbol]?: any
            } = {}

          Parameters

          • arg: string | string[] | Record<string, number | boolean | object>

          Returns QueryWithHelpers<IfEquals<RawDocTypeOverride, {}, ResultType, ResultType extends any[]
              ? ResultType extends any[]
                  ? IfAny<RawDocTypeOverride, any, mongoose.Document<unknown, {}, RawDocTypeOverride> & Require_id<RawDocTypeOverride>>[]
                  : RawDocTypeOverride[]
              : ResultType extends any
                  ? IfAny<RawDocTypeOverride, any, mongoose.Document<unknown, {}, RawDocTypeOverride> & Require_id<RawDocTypeOverride>>
                  : RawDocTypeOverride>, DocType, THelpers, IfEquals<RawDocTypeOverride, {}, RawDocType, RawDocTypeOverride>, QueryOp>

        • Determines if field selection has been made.

          Returns boolean

        • Determines if exclusive field selection has been made.

          Returns boolean

        • Determines if inclusive field selection has been made.

          Returns boolean

        • Sets the MongoDB session associated with this query. Sessions are how you mark a query as part of a transaction.

          Parameters

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Adds a $set to this query's update without changing the operation. This is useful for query middleware so you can add an update regardless of whether you use updateOne(), updateMany(), findOneAndUpdate(), etc.

          Parameters

          • path: string | Record<string, unknown>
          • Optional value: any
            Optional

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets query options. Some options only make sense for certain operations.

          Parameters

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets the query conditions to the provided JSON object.

          Parameters

          Returns void

        • Specifies an $size query condition. When called with one argument, the most recent path passed to where() is used.

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies the number of documents to skip.

          Parameters

          • val: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a $slice projection for an array.

          Parameters

          • path: string
          • val: number | number[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • val: number | number[]

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets the sort order. If an object is passed, values allowed are asc, desc, ascending, descending, 1, and -1.

          Parameters

          • Optional arg: string | {
                [key: string]: SortOrder | {
                    $meta: any;
                };
            } | [string, SortOrder][]
            Optional

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Sets the tailable option (for use with capped collections).

          Parameters

          • Optional bool: boolean
            Optional
          • Optional opts: {
                numberOfRetries?: number;
                tailableRetryInterval?: number;
            }
            Optional
            • Optional numberOfRetries?: number
            • Optional tailableRetryInterval?: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Converts this query to a customized, reusable query constructor with all arguments and options retained.

          Type Parameters

          Returns RetType

        • Runs a function fn and treats the return value of fn as the new value for the query to resolve to.

          Type Parameters

          • MappedType

          Parameters

          • fn: ((doc) => MappedType)
              • (doc): MappedType
              • Parameters

                • doc: ResultType

                Returns MappedType

          Returns QueryWithHelpers<MappedType, DocType, THelpers, RawDocType, QueryOp>

        • Declare and/or execute this query as an updateMany() operation. Same as update(), except MongoDB will update all documents that match filter (as opposed to just the first one) regardless of the value of the multi option.

          Parameters

          Returns QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, "updateMany">

        • Sets the specified number of mongod servers, or tag set of mongod servers, that must acknowledge this write before this write is considered successful.

          Parameters

          • val: string | number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Specifies a path for use with chaining.

          Parameters

          • path: string
          • Optional val: any
            Optional

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Parameters

          • obj: object

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • Defines a $within or $geoWithin argument for geo-spatial queries.

          Parameters

          • Optional val: any
            Optional

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        • If w > 1, the maximum amount of time to wait for this write to propagate through the replica set before this operation fails. The default is 0, which means no timeout.

          Parameters

          • ms: number

          Returns Query<ResultType, DocType, THelpers, RawDocType, QueryOp>

        Generated using TypeDoc