All Collections
Portal-X Pages
Design | Cloud Data | Custom Entities
Design | Cloud Data | Custom Entities

Create and modify collections of custom entities of your app

Jason Liang avatar
Written by Jason Liang
Updated over a week ago

Note - Custom Entities are a Plus Plan feature. Choose from one of many Plus Plans (including the $5 / month Development Plus Plan) to gain access.

Benefits

Custom Entities are the super-charged versions of Global and User Entities. It comes with all the features of our standard entity systems (with ownership, ACL, time-to-live, and concurrency versioning) - plus support for Custom Indexes (i.e. much faster!) and Deployment Migration (i.e. more convenient!). We especially recommend them for cases where you have large datasets with many ways in which that data will be accessed.

Custom Entities are similar to both Global Entities and User Entities - with some definite performance advantages - since you can create custom indexes for them. Indexes support the efficient execution of queries. Without them, the database must scan every document in a collection to select those that match the query statement. If an appropriate index exists for a query, the database can use the index to narrow down the number of documents it must inspect.

To achieve these benefits, you must "define" your Custom Entities ahead of time - that's where we attach the index meta-data and such. By comparison, Global Entities and User Entities are essentially "untyped".

Here's the key thing - there are two major classifications of Custom Entities - those that are "owned" (i.e. owned by users) and "unowned".

Unowned Custom Entities are very much like Global Entities (specifically what we refer to as System Entities - which are the property of the app and not a specific user), they also include deployment app data migration support - so you can easily push app data updated from development to production.

Owned Custom Entities, however, are very much like User Entities, you get all the same concepts as Privacy (they are private to individual players - controlled by ACL), concurrency versioning, etc.

You can even view the entities owned by a player within User Data - which is of course very convenient (and feels very much like User Entities).

That said - you can also view the entire Owned Custom Entity collection at the Global Monitoring level - which can be helpful if you want to search for all players that have reached level 40 or something. This is something that cannot be done with User Entities.

In the grand scheme of things, unowned Custom Entities are much better than Global Entities. And owned Custom Entities are better than User Entities.

Design Portal

The following Portal Pages allow you to easily manipulate Custom Entities:

  • Design | Cloud Data | Custom Entities - allow you to define Custom Entities, their Custom Indexes, and even handy JSON templates for creating new entities.

  • Global | Global Data | Custom Entities - View and edit all entity collections - with full search and Import/Export functionality.

  • User | Data | Custom Entities - Easily view/edit the entities owned by a specific user.

Create a Custom Entity

Step 1: Create a Custom Entity Type if don’t have one or want to create a new one: click the [Create...] button on Design | Cloud Data | Custom Entity collections page, and a pop-up window will appear.

  • Entity Type Name (required, as the collection's name)

  • Identifier (optional, is utilized to display the value of the designated field when viewing the entities list from the portal. The default identifier setting location is the root-level fields of your entity data, do not prefix data. for the field name)

  • Owned (default to unowned, if set, instances of this entity type must be owned by users, similar to user entities.)

  • Migrate (default to false, if set, instances of this entity type will be migrated during a deploy/export operation, similar to global entities. This option is only for unowned entities.)

  • Template Data (optional, is used to set up a template of data input for this collection, making you create entity instances in the portal easier, no need to create from scratch)

Add indexes

It is not mandatory, but it is the most advantageous aspect of custom entities. It is highly recommended to create indexes for large datasets that retrieve fixed pattern data frequently to achieve better performance. Once an Entity Type is created, click this type entry row to open the Entity Type Details blade, then click the [View..] button to open a pop-up, switch to the Custom Indextex tab click [Edit]-> [Create...] to add an index for this collection.

Add the field name (indexed keys) and each key's direction (i.e. 1 or -1 ) pair inside the text box of Keys, and add some options (i.e. index properties, such as sparse, partial, TTL, case insensitive) to the index you are adding inside the text box of Options (refer to MongoDB Index Properties for details). The commonly used index types in brainCloud include Single Field Indexes and Compound Indexes (Compound indexes can support queries that match on multiple fields).

  • The option of background is set to true by default since this is the only safe way to create an index when the system is live.

  • The option of sparse is set to true by default for the indexed fields that may be missing in some documents, it will skip over any documents that are missing the indexed fields.

Did this answer your question?