Skip to main content

Collection Spec

A _collection/spec is set of smart functions that are attached to a particular collection. Any time that collection appears in a transaction, regardless of who issues the transaction, the smart functions attached to the _collection/spec will execute.

If all of the smart functions return true, the transaction will succeed. If any of the smart functions return false, it will fail.

Uses#

The most common use for collection specs to make sure a certain predicate is included in a collection. For example, the below spec, the function makes sure person/fullName is required.

[  {    "_id": ["_collection/name", "person"],    "spec": ["_fn$fullNameReq"],    "specDoc": "A person is required to have a fullName."  },  {    "_id": "_fn$fullNameReq",    "name": "fullNameReq",    "code": "(boolean (get (query (str \"{\\\"select\\\": [\\\"*\\\"], \\\"from\\\":\" (?sid) \"}\")) \"person/fullName\"))"  }]