SDK
SDK Javascript v5.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.

create #

Creates a new collection in the provided index.

Available since 1.3.0

You can also provide an optional data mapping that allow you to exploit the full capabilities of our persistent data storage layer, ElasticSearch (check here the mapping capabilities of ElasticSearch).

This method will only update the mapping if the collection already exists.


create([mapping], [options], [callback]) #

ArgumentsTypeDescription
mappingJSON ObjectOptional data mapping
optionsJSON ObjectOptional parameters
callbackfunctionOptional callback

Options #

OptionTypeDescriptionDefault
queuablebooleanMake this request queuable or nottrue

Return Ralue #

Returns the Collection object to allow chaining.


Callback Response #

Returns a JSON object containing the raw Kuzzle response.

Usage #

// Optional: a mapping can be provided and will be
// applied when the collection is created
const mapping = {
  properties: {
    field1: {
      type: '<es field type>'
    },
    field2: {
      type: '<es field type>'
    }
  }
};
// Using callbacks (NodeJS or Web Browser)
kuzzle
  .collection('collection', 'index')
  .create(mapping, function (error, result) {
    // callback called once the create operation has completed
    // => the result is a JSON object containing the raw Kuzzle response:
    // {
    //    acknowledged: true
    // }
  });
// Using promises (NodeJS only)
kuzzle
  .collection('collection', 'index')
  .createPromise(mapping)
  .then(result => {
    // promise resolved once the create operation has completed
    // => the result is a JSON object containing the raw Kuzzle response:
    // {
    //    acknowledged: true
    // }
  });

Callback response:

{
  "status": 200,
  "error": null,
  "requestId": "<request unique identifier>",
  "controller": "collection",
  "action": "create",
  "collection": "<new collection name>",
  "index": "index",
  "volatile": null,
  "result": {
    "acknowledged": true
  }
}