Properties

$locals

$locals: Record<string, unknown>

Empty object that you can use for storing properties on the document. This is handy for passing data to middleware without conflicting with Mongoose internals.

$op

$op: null | "remove" | "save" | "validate"

A string containing the current operation that Mongoose is executing on this document. Can be null, 'save', 'validate', or 'remove'.

$where

$where: Record<string, unknown>

Set this property to add additional query filters when Mongoose saves this document and isNew is false.

__v

__v?: any

This documents __v.

_id

_id?: any

This documents _id.

baseModelName

baseModelName?: string

If this is a discriminator model, baseModelName is the name of the base model.

collection

collection: Collection<Document>

Collection the model uses.

db

db: Connection

Connection the model uses.

errors

errors?: ValidationError

Returns the current validation errors.

id

id?: any

The string version of this documents _id.

isNew

isNew: boolean

Boolean flag specifying if the document is new.

modelName

modelName: string

The name of the model

schema

schema: Schema<any, Model<any, any, any, any, any>, {}, {}, {}, {}, "type", {}>

The document's schema.

Methods

$assertPopulated

<Paths>(path: string | string[], values?: Partial<Paths>): Omit<IPodcastEpisode, keyof Paths> & Paths

Assert that a given path or paths is populated. Throws an error if not populated.

$getAllSubdocs

(): Document<any, any, any>[]

$getPopulatedDocs

(): Document<any, any, any>[]

Returns an array of all populated documents associated with the query

$ignore

(path: string): void

Don't run validation on this path or persist changes to this path.

$inc

(path: string | string[], val?: number): IPodcastEpisode

Increments the numeric value at path by the given val. When you call save() on this document, Mongoose will send a $inc as opposed to a $set.

$isDefault

(path: string): boolean

Checks if a path is set to its default.

$isDeleted

(val?: boolean): boolean

Getter/setter, determines whether the document was removed or not.

$isEmpty

(path: string): boolean

Returns true if the given path is nullish or only contains empty objects. Useful for determining whether this subdoc will get stripped out by the minimize option.

$isValid

(path: string): boolean

Checks if a path is invalid

$markValid

(path: string): void

Marks a path as valid, removing existing validation errors.

$model

<ModelType>(name: string): ModelType

Returns the model with the given name on this document's associated connection.

$parent

(): undefined | Document<any, any, any>

If this document is a subdocument or populated document, returns the document's parent. Returns undefined otherwise.

$session

(session?: null | ClientSession): null | ClientSession

Getter/setter around the session associated with this document. Used to automatically set session if you save() a doc that you got from a query with an associated session.

$set

(path: string, val: any, type: any, options?: DocumentSetOptions): IPodcastEpisode

Alias for set(), used internally to avoid conflicts

(path: string, val: any, options?: DocumentSetOptions): IPodcastEpisode

(value: any): IPodcastEpisode

delete

(options: QueryOptions<unknown>, callback: Callback<any>): void

Removes this document from the db.

(callback: Callback<any>): void

(options?: QueryOptions<unknown>): any

deleteOne

(options: QueryOptions<unknown>, callback: Callback<any>): void

Removes this document from the db.

(callback: Callback<any>): void

(options?: QueryOptions<unknown>): any

depopulate

(path?: string | string[]): IPodcastEpisode

Takes a populated field and returns it to its unpopulated state. If called with no arguments, then all populated fields are returned to their unpopulated state.

directModifiedPaths

(): string[]

Returns the list of paths that have been directly modified. A direct modified path is a path that you explicitly set, whether via doc.foo = 'bar', Object.assign(doc, { foo: 'bar' }), or doc.set('foo', 'bar').

equals

(doc: Document<any, any, any>): boolean

Returns true if this document is equal to another document.

Documents are considered equal when they have matching _ids, unless neither document has an _id, in which case this function falls back to using deepEqual().

get

(path: string, type?: any, options?: any): any

Returns the value of a path.

getChanges

(): UpdateQuery<IPodcastEpisode>

Returns the changes that happened to the document in the format that will be sent to MongoDB.

increment

(): IPodcastEpisode

Signal that we desire an increment of this documents version.

init

(obj: AnyObject, opts?: AnyObject, callback?: Callback<IPodcastEpisode>): IPodcastEpisode

Initializes the document without setters or marking anything modified. Called internally after a document is returned from mongodb. Normally, you do not need to call this function on your own.

invalidate

(path: string, errorMsg: string | NativeError, value?: any, kind?: string): null | NativeError

Marks a path as invalid, causing validation to fail.

isDirectModified

(path: string | string[]): boolean

Returns true if path was directly set and modified, else false.

isDirectSelected

(path: string): boolean

Checks if path was explicitly selected. If no projection, always returns true.

isInit

(path: string): boolean

Checks if path is in the init state, that is, it was set by Document#init() and not modified since.

isModified

(path?: string | string[]): boolean

Returns true if any of the given paths are modified, else false. If no arguments, returns true if any path in this document is modified.

isSelected

(path: string): boolean

Checks if path was selected in the source query which initialized this document.

markModified

(path: string, scope?: any): void

Marks the path as having pending changes to write to the db.

modifiedPaths

(options?: { includeChildren?: boolean }): string[]

Returns the list of paths that have been modified.

overwrite

(obj: AnyObject): IPodcastEpisode

Overwrite all values in this document with the values of obj, except for immutable properties. Behaves similarly to set(), except for it unsets all properties that aren't in obj.

populate

<Paths>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<MergeType<IPodcastEpisode, Paths>>

Populates document references.

<Paths>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<MergeType<IPodcastEpisode, Paths>>): void

<Paths>(path: string, select?: string | AnyObject, model?: Model<any, {}, {}, {}, any>, match?: AnyObject, options?: PopulateOptions): Promise<MergeType<IPodcastEpisode, Paths>>

<Paths>(path: string, select?: string | AnyObject, model?: Model<any, {}, {}, {}, any>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<MergeType<IPodcastEpisode, Paths>>): void

populated

(path: string): any

Gets _id(s) used during population of the given path. If the path was not populated, returns undefined.

remove

(options: QueryOptions<unknown>, callback: Callback<any>): void

Removes this document from the db.

(callback: Callback<any>): void

(options?: QueryOptions<unknown>): Promise<IPodcastEpisode>

replaceOne

(replacement?: AnyObject, options?: null | QueryOptions<unknown>, callback?: Callback<any>): Query<any, IPodcastEpisode, {}, IPodcastEpisode>

Sends a replaceOne command with this document _id as the query selector.

save

(options: SaveOptions, callback: Callback<IPodcastEpisode>): void

Saves this document by inserting a new document into the database if document.isNew is true, or sends an updateOne operation with just the modified paths if isNew is false.

(callback: Callback<IPodcastEpisode>): void

(options?: SaveOptions): Promise<IPodcastEpisode>

set

(path: string, val: any, type: any, options?: any): IPodcastEpisode

Sets the value of a path, or many paths.

(path: string, val: any, options?: any): IPodcastEpisode

(value: any): IPodcastEpisode

toJSON

<T>(options?: ToObjectOptions & { flattenMaps?: true }): FlattenMaps<T>

The return value of this method is used in calls to JSON.stringify(doc).

<T>(options: ToObjectOptions & { flattenMaps: false }): T

toObject

<T>(options?: ToObjectOptions): Require_id<T>

Converts this document into a plain-old JavaScript object (POJO).

unmarkModified

(path: string): void

Clears the modified state on the specified path.

update

(update?: UpdateWithAggregationPipeline | UpdateQuery<IPodcastEpisode>, options?: null | QueryOptions<unknown>, callback?: Callback<any>): Query<any, IPodcastEpisode, {}, IPodcastEpisode>

Sends an update command with this document _id as the query selector.

updateOne

(update?: UpdateWithAggregationPipeline | UpdateQuery<IPodcastEpisode>, options?: null | QueryOptions<unknown>, callback?: Callback<any>): Query<any, IPodcastEpisode, {}, IPodcastEpisode>

Sends an updateOne command with this document _id as the query selector.

validate

(pathsToValidate: PathsToValidate, options: AnyObject, callback: CallbackWithoutResult): void

Executes registered validation rules for this document.

(pathsToValidate: PathsToValidate, callback: CallbackWithoutResult): void

(callback: CallbackWithoutResult): void

(pathsToValidate?: PathsToValidate, options?: AnyObject): Promise<void>

(options: { pathsToSkip?: pathsToSkip }): Promise<void>

validateSync

(options: { pathsToSkip?: pathsToSkip }): null | ValidationError

Executes registered validation rules (skipping asynchronous validators) for this document.

(pathsToValidate?: PathsToValidate, options?: AnyObject): null | ValidationError