Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface PropertyParameter

Replicated from mognoose properties

export
interface

PropertyParameter

Hierarchy

  • PropertyParameter

Indexable

[key: string]: any

Replicated from mognoose properties

export
interface

PropertyParameter

Index

Properties

Optional _id

_id: boolean

should subdocuments get their own id?

default

true (Implicitly)

Optional alias

alias: string

Give the Property an alias in the output Note: you should include the alias as a variable in the class, but not with a prop decorator

example
class Dummy {
  @prop({ alias: "helloWorld" })
  public hello: string; // normal, with @prop
  public helloWorld: string; // is just for type Completion, will not be included in the DB
}

Optional autopopulate

autopopulate: boolean | Function | {}

This option as only an effect when the plugin mongoose-autopopulate is used

Optional default

default: any

Give the Property a default Value

Optional enum

enum: string[] | object

Only accept Values from the Enum(|Array)

Optional expires

expires: string | number

Should this property have an "expires" index?

link

https://docs.mongodb.com/manual/tutorial/expire-data

Optional immutable

immutable: boolean

Make a property read-only

example
class SomeClass {
 @prop({ immutable: true })
 public someprop: Readonly<string>;
}

Optional index

index: boolean

should this value get an index?

link

https://docs.mongodb.com/manual/indexes

Optional ref

ref: any

Reference an other Document (you should use Ref as Prop type)

Optional refPath

refPath: string

Take the Path and try to resolve it to a Model

Optional refType

refType: RefSchemaType

Override the ref's type {@link BasePropOptions.type} can be used too

default

ObjectId

Optional required

required: RequiredType

is this value required?

default

false (Implicitly)

Optional select

select: boolean

include this value?

default

true (Implicitly)

Optional sparse

sparse: boolean

Optional text

text: boolean

Should this property have an "text" index?

link

https://mongoosejs.com/docs/api.html#schematype_SchemaType-text

Optional type

type: any

This may be needed if get/set is used (this sets the type how it is saved to the DB)

Optional unique

unique: boolean

Optional validate

validate: Validator | Validator[]

Give an Validator RegExp or Function

Methods

Optional get

  • get(val: any): any
  • Set an Getter (Non-Virtual) to Post-process your value (when using get/set both are required) Please note that the option type is required, if get/set saves a different value than what is defined

    example
    function setHello(val: string): string {
      return val.toLowerCase()
    }
    function getHello(val: string): string {
    interface PropertyParameter {
      get?: Function;
      set?: Function;
    }
    class Dummy {
      @prop({ set: setHello, get: getHello }) // many options can be used, like required
      public hello: string;
    }

    Parameters

    • val: any

    Returns any

    The Value, but modified OR anything

Optional set

  • set(val: any): any
  • Set an Setter (Non-Virtual) to pre-process your value (when using get/set both are required) Please note that the option type is required, if get/set saves a different value than what is defined

    example
    function setHello(val: string): string {
      return val.toLowerCase()
    }
    function getHello(val: string): string {
      return val.toUpperCase();
    }
    class Dummy {
      @prop({ set: setHello, get: getHello }) // many options can be used, like required
      public hello: string;
    }

    Parameters

    • val: any

    Returns any

    The Value, but modified OR anything

Generated using TypeDoc