replaceOneFromMap method

void replaceOneFromMap(
  1. Map<String, Object> docMap, {
  2. int? index,
})

Same as replaceOne but in Map format. Schema: { replaceOne : { "filter" :

Implementation

void replaceOneFromMap(Map<String, Object> docMap, {int? index}) {
  var filterMap = docMap[bulkFilter];
  if (filterMap is! Map<String, Object>) {
    throw MongoDartError('The "$bulkFilter" key of the '
        '"$bulkReplaceOne" element '
        '${index == null ? '' : 'at index $index '}must '
        'contain a Map');
  }
  if (docMap[bulkReplacement] is! Map<String, Object>) {
    throw MongoDartError('The "$bulkReplacement" key of the '
        '"$bulkReplaceOne" element '
        '${index == null ? '' : 'at index $index '}must '
        'contain a Map');
  }
  if (docMap[bulkUpsert] != null && docMap[bulkUpsert] is! bool) {
    throw MongoDartError('The "$bulkUpsert" key of the '
        '"$bulkReplaceOne" element '
        '${index == null ? '' : 'at index $index '}must '
        'contain a bool');
  }
  if (docMap[bulkCollation] != null &&
      docMap[bulkCollation] is! CollationOptions &&
      docMap[bulkCollation] is! Map<String, dynamic>) {
    throw MongoDartError('The "$bulkCollation" key of the '
        '"$bulkReplaceOne" element '
        '${index == null ? '' : 'at index $index '}must '
        'contain a CollationOptions element or a Map representation '
        'of a collation');
  }
  if (docMap[bulkHint] != null && docMap[bulkHint] is! String) {
    throw MongoDartError('The "$bulkHint" key of the '
        '"$bulkReplaceOne" element '
        '${index == null ? '' : 'at index $index '}must '
        'contain a String');
  }
  if (docMap[bulkHintDocument] != null &&
      docMap[bulkHintDocument] is! Map<String, Object>) {
    throw MongoDartError('The "$bulkHintDocument" key of the '
        '"$bulkReplaceOne" element '
        '${index == null ? '' : 'at index $index '}must '
        'contain a Map');
  }
  replaceOne(ReplaceOneStatement(
      filterMap, docMap[bulkReplacement] as Map<String, Object>,
      upsert: docMap[bulkUpsert] as bool?,
      collation: docMap[bulkCollation] is Map<String, dynamic>
          ? CollationOptions.fromMap(
              docMap[bulkCollation] as Map<String, Object>)
          : docMap[bulkCollation] as CollationOptions?,
      hint: docMap[bulkHint] as String?,
      hintDocument: docMap[bulkHintDocument] as Map<String, Object>?));
}