upsert method

Future<Map<String, dynamic>> upsert(
  1. String index,
  2. String collection,
  3. String id,
  4. Map<String, dynamic> changes, {
  5. Map<String, dynamic> defaults = const {},
  6. bool waitForRefresh = false,
  7. int? retryOnConflict,
  8. bool? source,
})

####Applies a partial update to an existing document. If the document doesn't already exist, a new document is created.

index: index name \
collection: collection name \
id: unique identifier of the document to update \
changes: Partial changes to apply to the document

Optional

defaults: Fields to add to the document if it gets created waitForRefresh: if set to wait_for, Kuzzle will not respond until the update is indexed \
retryOnConflict: conflicts may occur if the same document gets updated multiple times within a short timespan, in a database cluster. You can set the retryOnConflict optional argument (with a retry count), to tell Kuzzle to retry the failing updates the specified amount of times before rejecting the request with an error. \
source: if set to true Kuzzle will return the updated document body in the response \\

Implementation

///
/// Optional
///
/// **[defaults]**: Fields to add to the document if it gets created
/// **[waitForRefresh]**: if set to wait_for, Kuzzle will not respond
/// until the update is indexed \\\
/// **[retryOnConflict]**: conflicts may occur if the same document gets updated multiple times within a short timespan, in a database cluster. You can set the retryOnConflict optional argument (with a retry count), to tell Kuzzle to retry the failing updates the specified amount of times before rejecting the request with an error. \\\
/// **[source]**: if set to true Kuzzle will return the updated document body in the response \\\
Future<Map<String, dynamic>> upsert(
  String index,
  String collection,
  String id,
  Map<String, dynamic> changes, {
  Map<String, dynamic> defaults = const {},
  bool waitForRefresh = false,
  int? retryOnConflict,
  bool? source,
}) async {
  final response = await kuzzle.query(KuzzleRequest(
    controller: name,
    action: 'upsert',
    index: index,
    collection: collection,
    uid: id,
    body: {'changes': changes, 'defaults': defaults},
    waitForRefresh: waitForRefresh,
    source: source,
    retryOnConflict: retryOnConflict,
  ));

  return response.result as Map<String, dynamic>;
}