Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Model

Future features:

  • Autopopulate (Refs) -> FINISHED
  • Do Tests -> FINISHED
  • Custom Collections. -> FINISHED
  • Plugins -> FINISHED
  • General Hooks -> FINISHED
  • Properies edited flag
  • Schema Methods -> It's necesary? You can declare method in the class and that's fine.
  • Virtuals -> It's necesary? You can declare a getter and setter in the class and that's fine
  • MORE:
    • Recursive Save

Hierarchy

Index

Constructors

constructor

  • new Model(data?: object): Model
  • Creates an instance of Model with the corresponding metadata.

    memberof

    Model

    Parameters

    • Default value data: object = {}

    Returns Model

Properties

Private _id

_id: ObjectId

Virutal ID of document

memberof

Model

Accessors

Protected _key

  • get _key(): string
  • Key of collection

    memberof

    Model

    Returns string

Private _model

  • get _model(): MongooseModel<Document>
  • Return the Model reference

    readonly
    static
    memberof

    Model

    Returns MongooseModel<Document>

id

  • get id(): ObjectId
  • Getter for the virtual _id property

    readonly
    memberof

    Model

    Returns ObjectId

Methods

delete

Private doByCondicitonKey

  • doByCondicitonKey(key: PropMeta, prop: string, isFunction?: boolean): any
  • Execute a fucntion or get a prop value by condicion before and after

    memberof

    Model

    Parameters

    • key: PropMeta
    • prop: string
    • Default value isFunction: boolean = false

    Returns any

Private exists

  • exists(key: any): Promise<boolean>
  • Check if this document exist in DB by model key

    memberof

    Model

    Parameters

    • key: any

    Returns Promise<boolean>

get

  • get(target: any, prop: string): Promise<any>

getId

Private getMetadata

  • getMetadata(where: string | symbol, target: any): void
  • Get metadata on model

    memberof

    Model

    Parameters

    • where: string | symbol
    • target: any

    Returns void

Private getQueryKey

  • getQueryKey(key: any): object
  • Get key

    memberof

    Model

    Parameters

    • key: any

    Returns object

save

  • save(): Promise<this>
  • Save/Create a register of the document in the database and return the instance

    memberof

    Model

    Returns Promise<this>

set

  • set(target: any, prop: string, value: any): boolean

Private setMetadata

  • setMetadata(where: string | symbol, data: any, classConstructor: any): void
  • Set metadata on model

    memberof

    Model

    Parameters

    • where: string | symbol
    • data: any
    • classConstructor: any

    Returns void

update

  • update(data?: object): Promise<this>
  • Update a record in the database and return the instance

    memberof

    Model

    Parameters

    • Optional data: object

    Returns Promise<this>

Static Private assign

  • assign(properties: object): void
  • Assing all properties to object when this is created.

    memberof

    Model

    Parameters

    • properties: object

    Returns void

Static create

  • create<T>(this: StaticThis<T>, data: object): Promise<T>
  • Create a register of the document in the database and return the instance

    static
    memberof

    Model

    Type parameters

    Parameters

    Returns Promise<T>

Static deleteMany

Static Private docToClass

  • docToClass(document: Document): any
  • Parse mongo document to instance of the class

    static
    template
    memberof

    Model

    Parameters

    • document: Document

    Returns any

Static Private docsToClass

  • docsToClass(documents: Document[]): any[]
  • Parse mongo document array to instance array

    static
    template
    memberof

    Model

    Parameters

    • documents: Document[]

    Returns any[]

Static find

  • find<T>(this: StaticThis<T>, query?: object, populate?: string | object[] | object, selectFields?: string): Promise<T[]>
  • Return an array of document casted found in database

    static
    memberof

    Model

    Type parameters

    Parameters

    • this: StaticThis<T>
    • Default value query: object = {}
    • Default value populate: string | object[] | object = ""
    • Default value selectFields: string = ""

    Returns Promise<T[]>

Static findById

  • findById<T>(this: StaticThis<T>, id: string | ObjectId, populate?: string | object[] | object, selectFields?: string): Promise<T>
  • Return one document from database by ID

    static
    memberof

    Model

    Type parameters

    Parameters

    • this: StaticThis<T>
    • id: string | ObjectId
    • Default value populate: string | object[] | object = ""
    • Default value selectFields: string = ""

    Returns Promise<T>

Static findOne

  • findOne<T>(this: StaticThis<T>, query?: object, populate?: string | object[] | object, selectFields?: string): Promise<T>
  • Return one document from database by the query

    static
    memberof

    Model

    Type parameters

    Parameters

    • this: StaticThis<T>
    • Default value query: object = {}
    • Default value populate: string | object[] | object = ""
    • Default value selectFields: string = ""

    Returns Promise<T>

Static Private objToClass

  • objToClass(obj: object, document: Document): any
  • Parse mongo document to instance of the class

    static
    template
    memberof

    Model

    Parameters

    • obj: object
    • document: Document

    Returns any

Generated using TypeDoc