write method

Future<Map<String, dynamic>> write(
  1. String index,
  2. String collection,
  3. Map<String, dynamic> document, {
  4. String? id,
  5. bool waitForRefresh = false,
})

Creates or replaces a document

Implementation

Future<Map<String, dynamic>> write(
  String index,
  String collection,
  Map<String, dynamic> document, {
  String? id,
  bool waitForRefresh = false,
}) async {
  final response = await kuzzle.query(KuzzleRequest(
    action: 'write',
    collection: collection,
    controller: name,
    index: index,
    body: document,
    uid: id,
    waitForRefresh: waitForRefresh,
  ));

  if (response.result != null) {
    return response.result as Map<String, dynamic>;
  }

  throw BadResponseFormatError(
      response.error?.id, '$name.exists: bad response format', response);
}