Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Document<T, TQueryHelpers, DocType>

Generic types for Document:

  • T - the type of _id
  • TQueryHelpers - Object with any helpers that should be mixed into the Query type
  • DocType - the type of the actual Document created

Type Parameters

  • T = any

  • TQueryHelpers = any

  • DocType = any

Hierarchy

Index

Constructors

  • new Document<T, TQueryHelpers, DocType>(doc?: any): <internal>.Document<T, TQueryHelpers, DocType>
  • Type Parameters

    • T = any

    • TQueryHelpers = any

    • DocType = any

    Parameters

    • Optional doc: any

    Returns <internal>.Document<T, TQueryHelpers, DocType>

Properties

_id?: T

This documents _id.

__v?: any

This documents __v.

$locals: <internal>.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: "remove" | "save" | "validate"

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

$where: <internal>.Record<string, unknown>

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

baseModelName?: string

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

Collection the model uses.

Connection the model uses.

Returns the current validation errors.

id?: any

The string version of this documents _id.

isNew: boolean

Boolean flag specifying if the document is new.

schema: Schema<any, <internal>.Model<any, any, any, any, any>, {}, {}, {}, {}, DefaultSchemaOptions, {}>

The document's schema.

Methods

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

    Type Parameters

    • Paths = {}

    Parameters

    • path: string | string[]
    • Optional values: Partial<Paths>

    Returns <internal>.Omit<<internal>.Document<T, TQueryHelpers, DocType>, keyof Paths> & Paths

  • Returns a deep clone of this document

    Returns <internal>.Document<T, TQueryHelpers, DocType>

  • Returns <internal>.Document<any, any, any>[]

  • $ignore(path: string): void
  • Don't run validation on this path or persist changes to this path.

    Parameters

    • path: string

    Returns void

  • $isDefault(path: string): boolean
  • Checks if a path is set to its default.

    Parameters

    • path: string

    Returns boolean

  • $isDeleted(val?: boolean): boolean
  • Getter/setter, determines whether the document was removed or not.

    Parameters

    • Optional val: boolean

    Returns boolean

  • Returns an array of all populated documents associated with the query

    Returns <internal>.Document<any, any, any>[]

  • $inc(path: string | string[], val?: number): <internal>.Document<T, TQueryHelpers, DocType>
  • 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.

    Parameters

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

    Returns <internal>.Document<T, TQueryHelpers, DocType>

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

    Parameters

    • path: string

    Returns boolean

  • $isValid(path: string): boolean
  • Checks if a path is invalid

    Parameters

    • path: string

    Returns boolean

  • $markValid(path: string): void
  • Marks a path as valid, removing existing validation errors.

    Parameters

    • path: string

    Returns void

  • $model<ModelType>(name: string): ModelType
  • Returns the model with the given name on this document's associated connection.

    Type Parameters

    Parameters

    • name: string

    Returns ModelType

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

    Parameters

    Returns ClientSession

  • Alias for set(), used internally to avoid conflicts

    Parameters

    Returns <internal>.Document<T, TQueryHelpers, DocType>

  • Parameters

    Returns <internal>.Document<T, TQueryHelpers, DocType>

  • Parameters

    • value: any

    Returns <internal>.Document<T, TQueryHelpers, DocType>

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

    Parameters

    • Optional path: string | string[]

    Returns <internal>.Document<T, TQueryHelpers, DocType>

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

    Returns string[]

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

    Parameters

    Returns boolean

  • get(path: string, type?: any, options?: any): any
  • Returns the value of a path.

    Parameters

    • path: string
    • Optional type: any
    • Optional options: any

    Returns any

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

    Returns UpdateQuery<<internal>.Document<T, TQueryHelpers, DocType>>

  • Signal that we desire an increment of this documents version.

    Returns <internal>.Document<T, TQueryHelpers, DocType>

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

    Parameters

    Returns <internal>.Document<T, TQueryHelpers, DocType>

  • Marks a path as invalid, causing validation to fail.

    Parameters

    • path: string
    • errorMsg: string | NativeError
    • Optional value: any
    • Optional kind: string

    Returns NativeError

  • isDirectModified(path: string | string[]): boolean
  • Returns true if path was directly set and modified, else false.

    Parameters

    • path: string | string[]

    Returns boolean

  • isDirectSelected(path: string): boolean
  • Checks if path was explicitly selected. If no projection, always returns true.

    Parameters

    • path: string

    Returns boolean

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

    Parameters

    • path: string

    Returns boolean

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

    Parameters

    • Optional path: string | string[]

    Returns boolean

  • isSelected(path: string): boolean
  • Checks if path was selected in the source query which initialized this document.

    Parameters

    • path: string

    Returns boolean

  • markModified(path: string, scope?: any): void
  • Marks the path as having pending changes to write to the db.

    Parameters

    • path: string
    • Optional scope: any

    Returns void

  • modifiedPaths(options?: { includeChildren?: boolean }): string[]
  • Returns the list of paths that have been modified.

    Parameters

    • Optional options: { includeChildren?: boolean }
      • Optional includeChildren?: boolean

    Returns string[]

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

    Parameters

    Returns <internal>.Document<T, TQueryHelpers, DocType>

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

    Returns <internal>.Document<any, any, any>

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

    Parameters

    • path: string

    Returns any

  • Removes this document from the db.

    Parameters

    Returns void

  • Parameters

    Returns void

  • Parameters

    Returns Promise<<internal>.Document<T, TQueryHelpers, DocType>>

  • Sets the value of a path, or many paths.

    Parameters

    • path: string
    • val: any
    • type: any
    • Optional options: any

    Returns <internal>.Document<T, TQueryHelpers, DocType>

  • Parameters

    • path: string
    • val: any
    • Optional options: any

    Returns <internal>.Document<T, TQueryHelpers, DocType>

  • Parameters

    • value: any

    Returns <internal>.Document<T, TQueryHelpers, DocType>

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

    Type Parameters

    Parameters

    Returns FlattenMaps<T>

  • Type Parameters

    Parameters

    Returns T

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

    Type Parameters

    Parameters

    Returns Require_id<T>

  • unmarkModified(path: string): void
  • Clears the modified state on the specified path.

    Parameters

    • path: string

    Returns void

  • Executes registered validation rules for this document.

    Parameters

    Returns void

  • Parameters

    Returns void

  • Parameters

    Returns void

  • Parameters

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

Generated using TypeDoc