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

Type Parameters

  • ResultType
  • DocType
  • THelpers = {}
  • RawDocType = DocType
  • QueryOp = "find"

Implements

Constructors

Properties

[toStringTag]: string
_mongooseOptions: MongooseQueryOptions<DocType>
catch: (<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 declaration

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

Executes the query returning a Promise which will be resolved with .finally() chained.

Type declaration

    • (onfinally?): Promise<ResultType>
    • Parameters

      • Optional onfinally: (() => void)
          • (): 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>)

        Executes the query returning a Promise which will be resolved with either the doc(s) or rejected with the error.

        Type declaration

        Methods

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

        • Parameters

          • val: any[]

          Returns this

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

          Parameters

          • value: boolean

          Returns this

        • Specifies arguments for an $and condition.

          Parameters

          Returns this

        • Specifies the batchSize option.

          Parameters

          • val: number

          Returns this

        • Specifies a $box condition

          Parameters

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

          Returns this

        • Parameters

          • val: any

          Returns this

        • 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 obj: any

            If not set, defaults to this query's conditions

          Returns any

          the casted obj

        • Specifies a $center or $centerSphere condition.

          Parameters

          • path: string
          • area: any

          Returns this

        • Parameters

          • area: any

          Returns this

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

          Returns this

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

          Parameters

          Returns this

        • Specifies the comment option.

          Parameters

          • val: string

          Returns this

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

        • Parameters

          • val: any

          Returns this

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

          Parameters

          • val: any

          Returns this

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

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

        • Parameters

          • val: boolean

          Returns this

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

        • Specifies a $geometry condition

          Parameters

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

          Returns this

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

        • Parameters

          • val: number

          Returns this

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

        • Parameters

          • val: number

          Returns this

        • Sets query hints.

          Parameters

          • val: any

          Returns this

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

        • Parameters

          • val: any[]

          Returns this

        • Declares an intersects query for geometry().

          Parameters

          • Optional arg: any

          Returns this

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

          Parameters

          • val: boolean

          Returns this

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

          Parameters

          • val: number

          Returns this

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

        • Parameters

          • val: number

          Returns this

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

        • Parameters

          • val: number

          Returns this

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

        • Parameters

          • val: number

          Returns this

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

        • Merges another Query or conditions object into this one.

          Parameters

          Returns this

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

        • Parameters

          • val: number[]

          Returns this

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

        • Parameters

          • val: any

          Returns this

        • Specifies a $near or $nearSphere condition

          Type Parameters

          • K = string

          Parameters

          • path: K
          • val: any

          Returns this

        • Parameters

          • val: any

          Returns this

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

        • Parameters

          • val: any[]

          Returns this

        • Specifies arguments for an $nor condition.

          Parameters

          Returns this

        • Specifies arguments for an $or condition.

          Parameters

          Returns this

        • Specifies a $polygon condition

          Parameters

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

          Returns this

        • Parameters

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

          Returns this

        • 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[]

          Returns this

        • Sets the readConcern option for the query.

          Parameters

          • level: string

          Returns this

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

        • Parameters

          • val: string | RegExp

          Returns this

        • 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

        • 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

          Returns this

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

          Parameters

          Returns this

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

        • Parameters

          • val: number

          Returns this

        • Specifies the number of documents to skip.

          Parameters

          • val: number

          Returns this

        • Specifies a $slice projection for an array.

          Parameters

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

          Returns this

        • Parameters

          • val: number | number[]

          Returns this

        • 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][]

          Returns this

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

          Parameters

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

          Returns this

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

          Type Parameters

          Returns RetType

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

        • Specifies a path for use with chaining.

          Parameters

          • path: string
          • Optional val: any

          Returns this

        • Parameters

          • obj: object

          Returns this

        • Returns this

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

          Parameters

          • Optional val: any

          Returns this

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