Collections
April 17, 2019 ยท View on GitHub
Collections are the equivalent of a database table or entity.
Name
The name of a collection corresponds to its key in the collections
configuration property.
In the example below, it is users:
collections:
users:
attributes: {}
It is possible to differentiate between the name used server-side (anywhere in
the configuration) and client-side (in
URLs, method names, error responses and documentation) by specifying the
collection.name
configuration property.
In the example below, the server-side name is users and the client-side name
is players:
collections:
users:
name: players
attributes: {}
It is also possible to specify several client-side names, which will behave as
aliases, by using an array of names in collection.name.
collections:
users:
name: [users, players]
attributes: {}
Attributes
Attributes are the equivalent of a database column or key.
The name of an attribute corresponds to its key in the collection.attributes
configuration property. It
follows the same naming rules as collections.
In the example below, there is an attribute named age:
collections:
users:
attributes:
age: {}
Attributes called id are special as they:
- are used as primary key
- must be
required - are automatically created by the system, but can be overriden
Attribute type
One can specify an attribute.type among:
string(default)integernumber: includes both floating number and integerbooleanCOLLECTION: whereCOLLECTIONis the collection's name, e.g.users, for nested collectionsstring[],integer[],number[],boolean[]orCOLLECTION[]: same but as an array
Default collection
If a collection is called default, it will not be used as a regular
collection, but instead be deeply merged into each collection.
In the example below, each model's name will be required, and the
mongodb database will be used by default.
collections:
default:
database: mongodb
attributes:
name:
validate:
required: true
Empty values
Attributes with undefined or null values are considered empty, are treated
the same way and are converted to unset attributes.
Each example below is treated the same way and converted to the last form.
{ "name": "Bob", "weight": null }
{ "name": "Bob", "weight": undefined }
{ "name": "Bob" }
The exception is for patch
commands, where null is used to unset a value.