executeDocument method

Future<BulkWriteResult> executeDocument()

Implementation

Future<BulkWriteResult> executeDocument() async {
  var executionRetList = await executeBulk();
  BulkWriteResult? ret;
  WriteCommandType writeCommandType;

  for (var executionMap in executionRetList) {
    switch (executionMap['commandType']) {
      case keyInsert:
        writeCommandType = WriteCommandType.insert;
        break;
      case keyUpdate:
        writeCommandType = WriteCommandType.update;
        break;
      case keyDelete:
        writeCommandType = WriteCommandType.delete;
        break;
      default:
        throw StateError('Unknown command type');
    }
    if (ret == null) {
      ret = BulkWriteResult.fromMap(writeCommandType, executionMap);
    } else {
      ret.mergeFromMap(writeCommandType, executionMap);
    }
  }
  if (ret == null) {
    throw MongoDartError('No response from the server');
  }
  ret.ids = ids.sublist(0, min<int>(ids.length, ret.nInserted));
  return ret;
}