Functions for defining a collection schema.
Functions for defining a collection schema.
(any & options)
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>
: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? |
: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? | | `: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>)
Field must be a boolean
.
Parameter | Description |
---|---|
:optional? | optional boolean Is the field optional? |
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? | **Examples** ```Clojure ; field-1 must be a boolean and must be included: (create-collection! :coll :schema {:field-1 (boolean)}) ```
(date-time & :optional? <boolean>)
Field must be a java.util.Date
object.
Parameter | Description |
---|---|
:optional? | optional boolean Is the field optional? |
Examples
; Set field-1 to current date and time:
(create-collection! :coll :schema {:field-1 (java.util.Date.)})
Field must be a `java.util.Date` object. | Parameter | Description | | --- | --- | | `:optional?` | `optional boolean` Is the field optional? | **Examples** ```Clojure ; Set field-1 to current date and time: (create-collection! :coll :schema {:field-1 (java.util.Date.)}) ```
(id & :optional? <boolean>)
Field must be an ObjectId
.
Parameter | Description |
---|---|
:optional? | optional boolean Is the field optional? |
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? | **Examples** ```Clojure ; field-1 must be an ObjectId and can be excluded: (create-collection! :coll :schema {:field-1 (id :optional? true)}) ```
(integer &
:optional? <boolean>
: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? |
: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? | | `: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>)
Field must be a map
.
Parameter | Description |
---|---|
:optional? | optional boolean Is the field optional? |
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? | **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>
: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? |
: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? | | `: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>
: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? |
: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? | | `: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)}) ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close