IncrementData
tip
This method is not sharding safe - and thus is not recommended for custom entities that you may want to shard for greater performance and scalability in the future. Consider using IncrementDataSharded() version of this method instead.
Increments the specified fields by the specified amount within custom entity data on the server, enforcing ownership/ACL permissions.
Service | Operation |
---|---|
customEntity | INCREMENT_DATA |
Method Parameters
Parameter | Description |
---|---|
entityType | The type of custom entity being updated. |
entityId | The id of custom entity being updated. |
fieldsJson | Specific fields, as JSON, within entity's custom data, with respective increment amount. |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string entityType = "athletes";
string entityId = "aaaa-bbbb-cccc-dddd";
string fieldsJson = "{ \"goals\": 3, \"assists\": 5 }";
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.CustomEntityService.IncrementData(entityType, entityId, fieldsJson, successCallback, failureCallback);
const char *entityType = "athletes";
const char *entityId = "aaaa-bbbb-cccc-dddd";
const char *fieldsJson = "{ \"goals\": 3, \"assists\": 5 }";
_bc->getCustomEntityService()->incrementData(entityType, entityId, fieldsJson, this);
NSString *entityType = @"athletes";
NSString *entityId = @"aaaa-bbbb-cccc-dddd";
NSString *fieldsJson = "{ \"goals\": 3, \"assists\": 5 }";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc customEntityService] incrementData:entityType
entityId:entityId
fieldsJson:fieldsJson
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String entityType = "athletes";
String entityId = "aaaa-bbbb-cccc-dddd";
string fieldsJson = "{ \"goals\": 3, \"assists\": 5 }";
this; // implements IServerCallback
_bc.getCustomEntityService().incrementData(entityType, entityId, fieldsJson, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var entityType = "athletes";
var entityId = "aaaa-bbbb-cccc-dddd";
var fieldsJson = {
"goals": 3,
"assists": 5
};
_bc.customEntity.incrementData(entityType, entityId, fieldsJson, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var entityType = "athletes";
var entityId = "aaaa-bbbb-cccc-dddd";
var fieldsJson = {
"goals": 3,
"assists": 5
};
ServerResponse result = await _bc.customEntityService.incrementData(entityType:entityType, entityId:entityId, fieldsJson:fieldsJson);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var entityType = "athletes";
var entityId = "aaaa-bbbb-cccc-dddd";
var fieldsJson = {
"goals": 3,
"assists": 5
};
var customEntityProxy = bridge.getCustomEntityServiceProxy();
var postResult = customEntityProxy.incrementData(entityType, entityId, fieldsJson);
if (postResult.status == 200) {
// Success!
}
{
"service": "customEntity",
"operation": "INCREMENT_DATA",
"data": {
"entityType": "athletes",
"entityId": "aaaa-bbbb-cccc-dddd",
"fieldsJson": {
"goals": 3,
"assists": 5
}
}
}
JSON Response
{
"data": {
"entityId": "aaaa-bbbb-cccc-dddd",
"version": 2,
"acl": {
"other": 2
},
"ownerId": null,
"expiresAt": null,
"timeToLive": null,
"createdAt": 1586047449214,
"updatedAt": 1591290232477,
"data": {
"goals": 3,
"assists": 5
},
"entityType": "athletes"
},
"status": 200
}