# Class: ArrayType
Array type supports arrays of SchemaTypes and arrays of subdocuments.
# Options
- required flag to define if the field is mandatory
- validator that will be applied to the field, allowed function, object or string with the name of the custom validator
- default that will define the initial value of the field, allowed and value or function to generate it
- immutable that will define this field as immutable. Ottoman prevents you from changing immutable fields if the schema as configure like strict
example
const postSchemaDef = new Schema({
postTags: [String],
comments: [{ type: commentSchema, ref: 'Comment' }],
});
2
3
4
# Hierarchy
↳ CoreType
↳ ArrayType
# Constructors
# constructor
+ new ArrayType(name
: string, itemType
: IOttomanType, options?
: CoreTypeOptions): ArrayType
Overrides CoreType.constructor
Parameters:
Name | Type |
---|---|
name | string |
itemType | IOttomanType |
options? | CoreTypeOptions |
Returns: ArrayType
# Properties
# itemType
• itemType: IOttomanType
# name
• name: string
Inherited from IOttomanType.name
# Optional
options
• options? : CoreTypeOptions
Inherited from CoreType.options
# typeName
• typeName: string
Inherited from IOttomanType.typeName
# Static
sName
▪ sName: string = Array.name
# Accessors
# default
• get default(): unknown
Inherited from CoreType.default
Returns: unknown
# required
• get required(): boolean | RequiredOption | RequiredFunction
Inherited from CoreType.required
Returns: boolean | RequiredOption | RequiredFunction
# validator
• get validator(): ValidatorOption | ValidatorFunction | string | undefined
Inherited from CoreType.validator
Returns: ValidatorOption | ValidatorFunction | string | undefined
# Methods
# buildDefault
▸ buildDefault(): unknown
Inherited from CoreType.buildDefault
Returns: unknown
# cast
▸ cast(value
: unknown, strategy
: CAST_STRATEGY): unknown
Overrides IOttomanType.cast
Parameters:
Name | Type | Default |
---|---|---|
value | unknown | - |
strategy | CAST_STRATEGY | CAST_STRATEGY.DEFAULT_OR_DROP |
Returns: unknown
# checkRequired
▸ checkRequired(): string | void
Inherited from CoreType.checkRequired
Returns: string | void
# checkValidator
▸ checkValidator(value
: unknown): void
Inherited from CoreType.checkValidator
Parameters:
Name | Type |
---|---|
value | unknown |
Returns: void
# isEmpty
▸ isEmpty(value
: unknown): boolean
Inherited from CoreType.isEmpty
Parameters:
Name | Type |
---|---|
value | unknown |
Returns: boolean
# isStrictStrategy
▸ isStrictStrategy(strategy
: VALIDATION_STRATEGY): boolean
Inherited from CoreType.isStrictStrategy
Parameters:
Name | Type |
---|---|
strategy | VALIDATION_STRATEGY |
Returns: boolean
# validate
▸ validate(value
: unknown, strict
: boolean): unknown
Parameters:
Name | Type | Default |
---|---|---|
value | unknown | - |
strict | boolean | true |
Returns: unknown