Core
Guides v1.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

Specification Structure #

When a collection is created, its specification is empty. As a result, any document will be valid.

In order to update the specification, you can use the updateSpecifications action.

Here is an example of a full specification:

Copied to clipboard!
const specification = {
  myIndex: {
    myCollection: {
      // If true, the document will be rejected if it attemps to
      // define new fields that have not been defined in the schema.
      strict: true,

      // All documents will be rejected if they did not match theses fields validators
      fields: {
        fieldName: {
          mandatory: true,
          type: 'string',
          defaultValue: 'a default value',
          multivalued: {
            value: true,
            minCount: 1,
            maxCount: 5
          },
          typeOptions: {
            length: {
              min: 2,
              max: 12
            }
          }
        },
        anotherFieldName: {
          '...': '...'
        },
        myObjectField: {
          type: 'object',
          '...': '...'
        },
        'myObjectField/mySubField': {
          '...': '...'
        }
      },

      // Define custom conditional fields validators to reject document if they meet filters
      validators: ['...']
    },
    '...': '...'
  },
  '...': '...'
};

Learn how to create simple field validators and complex validators.