partialUpdateObject method
PartialUpdateObject
Updates fields in the object referred to by this AlgoliaObjectReference.
Values in data
may be of any supported Algolia type.
If no object exists yet, the update will fail.
Usage
createIfNotExists
: When true, a partial update on a nonexistent object will create the object, assuming an empty object as the basis. When false, a partial update on a nonexistent object will be ignored.
Implementation
Future<AlgoliaTask> partialUpdateObject(Map<String, dynamic> data,
{bool createIfNotExists = true}) async {
assert(_objectId != null || createIfNotExists,
'You can\'t partialUpdateObject when createIfNotExists=false and data without an objectID.');
assert(_index != null && _index != '*' && _index != '',
'IndexName is required, but it has `*` multiple flag or `null`.');
var url = 'indexes/$encodedIndex';
if (_objectId != null) {
url = '$url/$encodedObjectID/partial';
}
data['objectID'] = _objectId;
data['createIfNotExists'] = createIfNotExists;
var response = await algolia._apiCall(
ApiRequestType.post,
url,
data: data,
);
Map<String, dynamic> body = json.decode(response.body);
if (!(response.statusCode >= 200 && response.statusCode < 300)) {
throw AlgoliaError._(body, response.statusCode);
}
return AlgoliaTask._(algolia, _index, body);
}