Global Entity
The following methods are used to work with Global Entities, which as the name implies, are accessible to all users of the application (within the confines of the ACL specified).
Performance warning: Global Entities are best-suited for a moderate number (i.e. < 1000) of generally read-only objects (i.e. think tuning files, level data, etc.)
Do not use Global Entities in cases where the data is primarily owned by users and the number of objects will grow as the user population grows. Use User Entities instead - or for maximum flexibility use Owned Custom Entities.
Also - if the data is un-owned, but high populations of objects are required (i.e. more than 1000), use Un-owned Custom Entities.
Note that the integrity of Global Entities are protected by two key mechanisms:
- Atomic writes – MongoDB enforces that only one write at a time can be processed on an object in the database. In this way, multiple users of an application cannot each partially update an object
- Version checking – brainCloud uses a versioning scheme on objects to ensure that the object you're attempting to update has not changed since you initially read it. See the versioning documentation for more information.
brainCloud versioning works like this:
- Entities (both Global and User/Player) each have a version associated with them
- This version is automatically incremented by the server each time an update is performed
- For a client update to be valid (and succeed), the client must provide the version in the update, and this version must match the current value stored in the database.
- If the version match, the update is processed (automatically incrementing the version), and a copy of the updated object is returned to the client
- If the versions don't match, an exception is triggered.
Entity versioning can by bypassed by passing a "-1" as the version in the update method – but this is not recommended.
There are two more unique capabilities of Global Entities:
- Indexing – global entities can be indexed for faster lookups.
- Time-to-live – you can optionally set the Time-to-live (TTL) for a Global Entity. This is very useful if you're using Global Entities to implement shared dynamic objects, that should automatically be cleaned up (based on inactivity)
Special Topic: Global Entity Ownership and Deletion
By default, every Global Entity is owned by the user that creates it - and will be automatically removed if/when that user that is deleted.
This may not be ideal for some use cases. For this purpose, brainCloud also supports System Entities - which are simply Global Entities without owners - and are therefore not subject to the delete when the owner is deleted rule.
The Global Entity service contains a subset API for dealing with System Entities. These API calls bypass most ACL rules, and are thus callable via cloud code scripts only.
Scaling Global Entities
API Summary
Core Access:
- CreateEntity
- CreateEntityWithIndexedId
- DeleteEntity
- UpdateEntity
- UpdateEntityAcl
- UpdateEntityTimeToLive
- UpdateEntityOwnerAndAcl
- IncrementGlobalEntityData
Retrieval
System Entities
System Entity calls are available via Cloud Code only.
- CreateSystemEntity
- GetSystemEntityList
- GetSystemEntityListCount
- GetSystemEntityPage
- GetSystemEntityPageOffset
- MakeSystemEntity
- ReadSystemEntity
- UpdateSystemEntity
- UpdateSysetmEntityAcl
- UpdateEntityIndexedId
For more information on how brainCloud organizes data, refer to the Cloud Data Overview.
📄️ CreateEntity
Method creates a new entity on the server.
📄️ CreateEntityWithIndexedId
Method creates a new entity on the server with an indexed ID.
📄️ CreateSystemEntity
Method creates a new system entity on the server.
📄️ CreateSystemEntityWithIndexedId
Create a new system entity on the server with an indexed id.
📄️ DeleteEntity
Method deletes the given entity on the server.
📄️ DeleteSystemEntity
Method deletes the given system entity on the server.
📄️ GetList
Method gets list of entities from the server base on type and/or where clause.
📄️ GetListByIndexedId
Method gets list of entities from the server base on indexed ID.
📄️ GetListCount
Method gets a count of entities based on the where clause.
📄️ GetListCountWithHint
Get a count of entities from the server base on where clause and hinting on index hint. Where clause allows entityType, createdAt, updatedAt, data items.
📄️ GetListWithHint
Get a list of entities from the server base on where clause and hinting on indicated index hint. Where clause allows entityType, createdAt, updatedAt, data items.
📄️ GetPage
Method uses a paging system to iterate through user entities.
📄️ GetPageOffset
Method to retrieve previous or next pages after having called the GetPage method.
📄️ GetRandomEntitiesMatching
Gets a list of up to randomCount randomly selected entities from the server based on the where condition and specified maximum return count.
📄️ GetRandomEntitiesMatchingWithHint
Gets a list of up to randomCount randomly selected entities from the server based on the where condition and specified maximum return count, using index hint provided.
📄️ GetSystemEntityList
Method gets list of system entities from the server base on type and/or where clause.
📄️ GetSystemEntityListCount
Method gets a count of system entities based on the where clause.
📄️ GetSystemEntityListCountWithHint
Get a count of system entities from the server base on where clause and hinting on index hint. Where clause allows entityType, createdAt, updatedAt, data items.
📄️ GetSystemEntityListWithHint
Get a list of system entities from the server base on where clause and hinting on indicated index hint. Where clause allows entityType, createdAt, updatedAt, data items.
📄️ GetSystemEntityPage
Method uses a paging system to iterate through global system entities.
📄️ GetSystemEntityPageOffset
Method to retrieve previous or next pages after having called the GetSystemEntityPage method.
📄️ IncrementGlobalEntityData
Partial increment of global entity data field items. Partial set of items incremented as specified.
📄️ MakeSystemEntity
Method clears an existing entity's owner and updates the ACL on the server.
📄️ ReadEntity
Method reads an existing entity from the server.
📄️ ReadSystemEntity
Method reads an existing system entity on the server. It cannot be an owned/global entity.
📄️ UpdateEntity
Method updates an entity on the server. This operation results in the entity data being completely replaced by the passed in JSON string.
📄️ UpdateEntityAcl
Method updates an existing entity's ACL on the server.
📄️ UpdateEntityIndexedId
Updates an existing entity's IndexedId on the server.
📄️ UpdateEntityOwnerAndAcl
Method updates an existing entity's owner and ACL on the server.
📄️ UpdateEntityTimeToLive
Method updates an existing entity's time to live on the server.
📄️ UpdateSystemEntity
Updates a System Entity, regardless of the ACL permissions of the object. This method is very useful when dealing with read-only system entities - since otherwise because they do not have an owner, they would not be editable at all. Note that for obvious security reasons, this API method is available via cloud-code only.
📄️ UpdateSystemEntityAcl
Updates an existing System Entity's ACL on the server, regardless of the entity's current ACL permissions. Note that for obvious security reasons, this API method is available via cloud-code only.