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.

subscribe #

Subscribes to this collection with a set of filters.

The provided callback will be called everytime a notification is received from Kuzzle.


subscribe(filters, [options], callback) #

ArgumentsTypeDescription
filtersJSON ObjectKoncorde Filters
optionsobject(Optional) Subscription configuration. Passed to the Room constructor.
callbackfunctionCallback to call every time a notification is received on this subscription

Options #

OptionTypeDescriptionDefault
volatileJSON ObjectAdditional information passed to notifications to other usersnull
scopestringFilter document notifications depending on their scope status. You may receive entering documents (scope: in), leaving documents (scope: out), all documents changes (scope: all) or filter these notifications completely (scope: none). This filter does not affect pub/sub messages or user events.all
statestringFilter document notifications depending on the state of the modifying request. You may receive real-time notifications when a document is about to be changed (state: pending), or be notified when the change has been fully written in the database (state: done), or both (state: all). This filter does not affect pub/sub messages or user events.done
subscribeToSelfboolean(Don't) subscribe to notifications fired as a consequence of our own queriestrue
usersstringFilter notifications fired upon a user entering the room (user: in), leaving the room (user: out), or both (user: all). Setting this variable to none prevents receiving these notificationsnone

The options object is directly passed to the Room constructor. See the Room object documentation for more information about these options and notifications.


Return Value #

Returns an object exposing the following method: onDone(callback)

The callback argument is called when the subscription ends, either successfully or with an error.

Usage #

kuzzle
  .collection('collection', 'index')
  .subscribe({equals: {title: 'foo'}}, function (error, result) {
    // called each time a new notification on this filter is received
    // check the Room/Notifications section of this documentation
    // to get notification examples
  })
  .onDone(function (err, roomObject) {
    // Handles the subscription result. Can be chained.
  });