Show Menu
Cheatography

kuzzle-js Cheat Sheet (DRAFT) by

A Kuzzle cheat sheet for Javascript

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Where to find docs

Protocols and ports

REST
7511
SocketIo
7512

Instan­tiate a Kuzzle connexion

var kuzzle = new Kuzzle(kuzzleUrl, {defaultIndex: 'defaultIndex'});
// kuzzleUrl example "http://localhost:7512"
 

dataCo­lle­cti­onF­actory

var collection = kuzzle.dataCollectionFactory('optional_Index', 'mandatory_collection');

create­Doc­ument

kuzzle
  .dataCollectionFactory('optional_index', 'mandatory_collection')
  .createDocument('optional_document_id', {document: 'object''}, {updateIfExist: true}, function (err, res) {
    // callback called once the create action has been completed
    // => the result is a KuzzleDocument object
  });

delete­Doc­ument

kuzzle
  .dataCollectionFactory('optional_index', 'mandatory_collection')
  .deleteDocument('mandatory_document_id', function (err, res) {
    // callback called once the delete action has been completed
    // => the result is an array containing the deleted document IDs
  });

subscribe

var mandatory_filter = {};
var optional_options = {};
var room =
  kuzzle
    .dataCollectionFactory('optional_index', 'mandatory_collection')
    .subscribe(mandatory_filter, optional_options,  function (error, result) {
      // called each time a new notification on this filter is received
    };

subscribe options

metadata
object
Additional inform­ation passed to notifi­cations to other users
scope
string (in, out, all, none) default 'all'
Does the document is entering or leaving the filter scope
state
string (pending, done, all) default 'done'
does the document is yet written or not
subscr­ibe­ToSelf
boolean (default true)
(Don't) subscribe to your own documents
users
string (in, out, all, none) default none
a user is (un)su­bsc­ribing to the same filter