executeModernMessage method

Future<Map<String, dynamic>> executeModernMessage(
  1. MongoModernMessage message, {
  2. Connection? connection,
  3. bool skipStateCheck = false,
})

Implementation

Future<Map<String, dynamic>> executeModernMessage(MongoModernMessage message,
    {Connection? connection, bool skipStateCheck = false}) async {
  if (skipStateCheck) {
    if (!_masterConnectionVerifiedAnyState.serverCapabilities.supportsOpMsg) {
      throw MongoDartError('The "modern message" can only be executed '
          'starting from release 3.6');
    }
  } else {
    if (state != State.open) {
      throw MongoDartError('DB is not open. $state');
    }
    if (!masterConnection.serverCapabilities.supportsOpMsg) {
      throw MongoDartError('The "modern message" can only be executed '
          'starting from release 3.6');
    }
  }

  connection ??= _masterConnectionVerifiedAnyState;

  var response = await connection.executeModernMessage(message);

  var section = response.sections.firstWhere((Section section) =>
      section.payloadType == MongoModernMessage.basePayloadType);
  return section.payload.content;
}