Functions for defining a collection schema.
Functions for defining a collection schema.
(any & :optional? <boolean>)Field can be of any type.
| Parameter | Description |
|---|---|
:optional? | optional boolean Is the field optional? |
Examples
(create-collection! :coll :schema {:field-1 (any)})
Field can be of any type.
| Parameter | Description
| --- | ---
| `:optional?` | `optional boolean` Is the field optional?
**Examples**
```clojure
(create-collection! :coll :schema {:field-1 (any)})
```(array <schema>
&
:optional?
<boolean>
:description
<string>
:min-length
<minimum
length>
:max-length
<maximum
length>
:unique?
<boolean>)Field must be an array.
| Parameter | Description |
|---|---|
schema | fn A call to a schema function. |
:optional? | optional boolean Is the field optional? |
:description | optional string Description for validation errors. |
:min-length | optional integer Minimum length of the array. |
:max-length | optional integer Maximum length of the array. |
:unique? | optional boolean Whether array values must be unique. |
Examples
; field-1 must be an array of strings and contain at least one element:
(create-collection! :coll :schema {:field-1 (array (string) :min-length 1)})
Field must be an `array`.
| Parameter | Description
| --- | ---
| `schema` | `fn` A call to a schema function.
| `:optional?` | `optional boolean` Is the field optional?
| `:description` | `optional string` Description for validation errors.
| `:min-length` | `optional integer` Minimum length of the array.
| `:max-length` | `optional integer` Maximum length of the array.
| `:unique?` | `optional boolean` Whether array values must be unique.
**Examples**
```clojure
; field-1 must be an array of strings and contain at least one element:
(create-collection! :coll :schema {:field-1 (array (string) :min-length 1)})
```(boolean & :optional? <boolean> :description <string>)Field must be a boolean.
| Parameter | Description |
|---|---|
:optional? | optional boolean Is the field optional? |
:description | optional string Description for validation errors. |
Examples
; field-1 must be a boolean and must be included:
(create-collection! :coll :schema {:field-1 (boolean)})
Field must be a `boolean`.
| Parameter | Description
| --- | ---
| `:optional?` | `optional boolean` Is the field optional?
| `:description` | `optional string` Description for validation errors.
**Examples**
```clojure
; field-1 must be a boolean and must be included:
(create-collection! :coll :schema {:field-1 (boolean)})
```(date-time & :optional? <boolean> :description <string>)Field must be a valid date-time object, default java.util.Date.
| Parameter | Description |
|---|---|
:optional? | optional boolean Is the field optional? |
:description | optional string Description for validation errors. |
Examples
; Set field-1 to current date and time:
(create-collection! :coll :schema {:field-1 (date-time)})
Field must be a valid date-time object, default `java.util.Date`.
| Parameter | Description
| --- | ---
| `:optional?` | `optional boolean` Is the field optional?
| `:description` | `optional string` Description for validation errors.
**Examples**
```clojure
; Set field-1 to current date and time:
(create-collection! :coll :schema {:field-1 (date-time)})
```(id & :optional? <boolean> :description <string>)Field must be an ObjectId.
| Parameter | Description |
|---|---|
:optional? | optional boolean Is the field optional? |
:description | optional string Description for validation errors. |
Examples
; field-1 must be an ObjectId and can be excluded:
(create-collection! :coll :schema {:field-1 (id :optional? true)})
Field must be an `ObjectId`.
| Parameter | Description
| --- | ---
| `:optional?` | `optional boolean` Is the field optional?
| `:description` | `optional string` Description for validation errors.
**Examples**
```clojure
; field-1 must be an ObjectId and can be excluded:
(create-collection! :coll :schema {:field-1 (id :optional? true)})
```(integer &
:optional? <boolean>
:description <string>
:in [<array of accepted values>]
:min <minimum>
:max <maximum>)Field must be an 8-byte long integer.
| Parameter | Description |
|---|---|
:optional? | optional boolean Is the field optional? |
:description | optional string Description for validation errors. |
:in | optional seq A collection of acceptable values. |
:min | optional integer Minimum value. |
:max | optional integer Maximum value. |
Examples
; field-1 must be an integer and must be included:
(create-collection! :coll :schema {:field-1 (integer)})
Field must be an 8-byte `long integer`.
| Parameter | Description
| --- | ---
| `:optional?` | `optional boolean` Is the field optional?
| `:description` | `optional string` Description for validation errors.
| `:in` | `optional seq` A collection of acceptable values.
| `:min` | `optional integer` Minimum value.
| `:max` | `optional integer` Maximum value.
**Examples**
```clojure
; field-1 must be an integer and must be included:
(create-collection! :coll :schema {:field-1 (integer)})
```(map & :optional? <boolean> :description <string>)Field must be a map.
| Parameter | Description |
|---|---|
:optional? | optional boolean Is the field optional? |
:description | optional string Description for validation errors. |
Examples
; Set field-1 to map containing two strings:
(create-collection! :coll :schema {:field-1 (map {:str-1 (string)
:str-2 (string)})})
Field must be a `map`.
| Parameter | Description
| --- | ---
| `:optional?` | `optional boolean` Is the field optional?
| `:description` | `optional string` Description for validation errors.
**Examples**
```clojure
; Set field-1 to map containing two strings:
(create-collection! :coll :schema {:field-1 (map {:str-1 (string)
:str-2 (string)})})
```(number &
:optional? <boolean>
:description <string>
:in [<array of accepted values>]
:min <minimum>
:max <maximum>)Field must be an 8-byte double.
| Parameter | Description |
|---|---|
:optional? | optional boolean Is the field optional? |
:description | optional string Description for validation errors. |
:in | optional seq A collection of acceptable values. |
:min | optional integer Minimum value. |
:max | optional integer Maximum value. |
Examples
; field-1 must be a number and must be included:
(create-collection! :coll :schema {:field-1 (number)})
Field must be an 8-byte `double`.
| Parameter | Description
| --- | ---
| `:optional?` | `optional boolean` Is the field optional?
| `:description` | `optional string` Description for validation errors.
| `:in` | `optional seq` A collection of acceptable values.
| `:min` | `optional integer` Minimum value.
| `:max` | `optional integer` Maximum value.
**Examples**
```clojure
; field-1 must be a number and must be included:
(create-collection! :coll :schema {:field-1 (number)})
```(string &
:optional?
<boolean>
:description
<string>
:in
[<array of accepted values>]
:regex
<regular
expression>
:min-length
<minimum
length>
:max-length
<maximum
length>)Field must be a string.
| Parameter | Description |
|---|---|
:optional? | optional boolean Is the field optional? |
:description | optional string Description for validation errors. |
:in | optional seq A collection of acceptable values. |
:regex | optional string A regular expression that values must pass. |
:min-length | optional integer Minimum length of the string. |
:max-length | optional integer Maximum length of the string. |
Examples
; field-1 must be a string and must be included:
(create-collection! :coll :schema {:field-1 (string)})
Field must be a `string`.
| Parameter | Description
| --- | ---
| `:optional?` | `optional boolean` Is the field optional?
| `:description` | `optional string` Description for validation errors.
| `:in` | `optional seq` A collection of acceptable values.
| `:regex` | `optional string` A regular expression that values must pass.
| `:min-length` | `optional integer` Minimum length of the string.
| `:max-length` | `optional integer` Maximum length of the string.
**Examples**
```clojure
; field-1 must be a string and must be included:
(create-collection! :coll :schema {:field-1 (string)})
```(timestamp & :optional? <boolean> :description <string>)Field must be a timestamp, i.e. a positive long integer.
| Parameter | Description |
|---|---|
:optional? | optional boolean Is the field optional? |
:description | optional string Description for validation errors. |
Examples
; field-1 must be an integer and must be included:
(create-collection! :coll :schema {:field-1 (timestamp)})
Field must be a `timestamp`, i.e. a positive `long integer`.
| Parameter | Description
| --- | ---
| `:optional?` | `optional boolean` Is the field optional?
| `:description` | `optional string` Description for validation errors.
**Examples**
```clojure
; field-1 must be an integer and must be included:
(create-collection! :coll :schema {:field-1 (timestamp)})
```cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |