elemMatch method

bool elemMatch(
  1. dynamic attributeValue,
  2. dynamic condition
)

This checks if attributeValue is an array, and if so at least one of the array items must match the condition

Implementation

bool elemMatch(dynamic attributeValue, dynamic condition) {
  // Loop through items in attributeValue
  if (attributeValue is List) {
    for (final item in attributeValue) {
      // If isOperatorObject(condition)
      if (isOperatorObject(condition)) {
        // If evalConditionValue(condition, item), break out of loop and
        //return true
        if (isEvalConditionValue(condition, item)) {
          return true;
        }
      }
      // Else if evalCondition(item, condition), break out of loop and
      //return true
      else if (isEvalCondition(item, condition)) {
        return true;
      }
    }
  }
  // If attributeValue is not an array, return false
  return false;
}