QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms and devices. Check out our detailed guides to make integration easy and fast.

Custom Objects

Learn how to store and sync data with QuickBlox key-value storage.

🚧

This is our new documentation for beta version of QuickBlox React Native SDK. Please contact our Customer Support Team to provide your feedback, suggestions, and requests to improve this page.

Custom Objects module provides flexibility to define any data structure (schema) you need, build one-to-many relations between schemas and control permissions for all operations made on data. Schema is defined in QuickBlox Dashboard.

There are two key concepts in Custom Objects:
- Class represents your schema and contains field names and types.
- Record represents the data you put into your schema.

Class and Record are similar to table and row in relational database. Every class in Custom Object module comes with five mandatory predefined fields: _id, user_id, parent_id, created_at, and updated_at.

Allowed data types: Integer (or Array of Integer); String (or Array of String); Float (or Array of Float); Boolean (or Array of Boolean); Location (Array of [, ]); File; Date.

Create class

To start using Custom Objects module, create a class:

  1. Go to QuickBlox Dashboard.
  2. Follow Custom => Add => Add new class direction. As a result, Add new class popup will appear.
  3. Enter a class name, add any fields you want.
  1. Click Create class button to create a new class.

Create records

To create a single object, use the code snippet below.

const customObject = {
  className: 'RNCustomObject2',
  fields: {
    text: 'Lorem ipsum dolor sit amen',
    version: 7,
    tags: [ '#test', '#customobjects', '#quickblox-react-native-sdk'],
    friendsIds: [ 12345, 12346, 12347 ]
  }
}

QB.objects
  .create(customObject)
  .then(function (cObject) { /* custom object created successfully */ })
  .catch(function (e) { /* handle error */ })

To create multiple objects, use the code snippet below.

const customObjects = {
  className: 'RNCustomObject2',
  objects: [{
    tags: [ '#test', '#customobjects', '#quickblox-react-native-sdk'],
    text: 'Lorem ipsum dolor sit amen 1',
    version: 1500
  }, {
    friendsIds: [],
    tags: [ '#test', '#customobjects', '#quickblox-react-native-sdk'],
    text: 'Lorem ipsum dolor sit amen 2',
    version: 1001
  }, {
    tags: [ '#test', '#customobjects', '#quickblox-react-native-sdk'],
    text: 'Lorem ipsum dolor sit amen 3',
    version: 13
  }]
}

QB.objects
  .create(customObjects)
  .then(function (cObjects) { /* custom objects created successfully */ })
  .catch(function (e) { /* handle error */ })

Retrieve records by IDs

To get records with a particular record ID, use the code snippet below.

const query = {
  className: 'RNCustomObject2',
  objectsIds: ['5d4175afa0eb4715cae5b63f']
}
QB.objects
  .get(query)
  .then(function (results) { /* records found by IDs */ })
  .catch(function (e) { /* handle error */ })

Retrieve records

To search for records of a particular class, apply the following code snippet.

const query = {
  className: 'RNCustomObject2',
  filter: {
    field: 'version',
    operator: QB.objects.OBJECTS_SEARCH_OPERATOR.FOR_TYPE.INTEGER.GTE,
    value: '1000'
  },
  sort: {
    ascending: false,
    field: 'created_at'
  }
}

QB.objects
  .get(query)
  .then(function (results) { /* records found */ })
  .catch(function (e) { /* handle error */ })

Here are operators and filters that you can use to retrieve records:

Filter

Applicable to types

Description

{field_name}

All types

Search records with the field which contains the specified value.

{field_name}[{search_operator}]

All types

Search a record with the field which contains the value according to the specified value and operator.

sort_asc

All types

Search results will be sorted by the specified field in ascending order.

sort_desc

All types

Search results will be sorted by the specified field in descending order.

skip

Integer

Skip N records in search results. Useful for pagination. Default (if not specified): 0

limit

Integer

Limit search results to N records. Useful for pagination. Default value: 100. Also can set to 1000. If limit is equal to 1, only the last record will be returned.

count

Integer

Count search results. Response will contain only count of records found.

output[include]

All types

The output parameter takes the form of a record with a list of fields for inclusion or exclusion from the result set. output[include] specifies the fields to include. The _id field is, by default, included in the result set. To exclude the _id field from the result set, you need to specify in the output[exclude] value the exclusion of the _id field.

output[exclude]

All types

The output parameter takes the form of a record with a list of fields for inclusion or exclusion from the result set. output[exclude] specifies the fields to exclude. The _id field is, by default, included in the result set. To exclude the _id field from the result set, you need to specify in the output[exclude] value the exclusion of the _id field.

near

Location

Search records in a specific radius with current position in meters. Format: field_name, longitude, latitude, radius (in meters).

Update records

You can update a single record using the code snippet below.

const payload = {
  className: customObject.className,
  id: customObject.id,
  fields: {
    text: 'Lorem ipsum dolor sit amen UPDATED',
    tags: {
      operator: QB.objects.OBJECTS_UPDATE_OPERATOR.FOR_TYPE.ARRAY.ADD_TO_SET,
      value: '#update',
    },
    friendsIds: {
      operator: QB.objects.OBJECTS_UPDATE_OPERATOR.FOR_TYPE.ARRAY.PULL,
      pullFilter: QB.objects.PULL_FILTER.IN,
      value: currentUser.id,
    },
    version: {
      operator: QB.objects.OBJECTS_UPDATE_OPERATOR.FOR_TYPE.INTEGER.INC,
      value: '1'
    }
  }
}

QB.objects
  .update(payload)
  .then(function (updated) { /* custom object updated successfully */ })
  .catch(function (e) { /* handle error */ })

You can update multiple records using the code snippet below.

const payload = {
  className: object1.className,
  objects: [{
    id: object1.id,
    fields: {
      text: `Lorem ipsum dolor sit amen UPDATED 123`,
      tags: [ '#update' ],
    },
  }, {
    id: object2.id,
    fields: {
      friendsIds: [ 1001001, 1001010 ],
      version: 1250
    }
  }]
}

QB.objects
  .update(payload)
  .then(function (updated) { /* items updated successfully */ })
  .catch(function (e) { /* handle errror */ })

Delete records

To delete single a record, use the code snippet below.

const payload = {
  className: object.className,
  ids: object.id
}
QB.objects
  .remove(payload)
  .then(function () { /* removed successfully */ })
  .catch(function (e) { /* handle error */ })

To delete multiple records, use the code snippet below.

const payload = {
  className: object1.className,
  ids: [ object1.id, object2.id ]
}
QB.objects
  .remove(payload)
  .then(function () { /* removed successfully */ })
  .catch(function (e) { /* handle error */ })

Relations

It is possible to create a relation between objects of two different classes via _parent_id field.

For example, we have the class Rating that contains score, review, and comment fields. We also have a Movie class. So we can create a record of class Rating that will point to the record of the class Movie via its _parent_id field, so the _parent_id field will contain the ID of record from class Movie.

🚧

Pay attention

This is not a simple soft link. This is actually a hard link. When you delete the Movie class record then all its children (records of class Rating with _parent_id field set to the Movie class record ID) will be automatically deleted as well.

📘

Note

If you need to retrieve all children, you can retrieve records with the filter _parent_id=<id_of_parent_class_record>.

Updated 2 months ago


What's Next

Address Book

Custom Objects


Learn how to store and sync data with QuickBlox key-value storage.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.