docs: function (operand, valueSelector, matcher) {                                      // 681
        if (!isPlainObject(operand))                                                                            // 682
          throw Error("$elemMatch need an object");                                                             // 683
                                                                                                                // 684
        var subMatcher, isDocMatcher;                                                                           // 685
        if (isOperatorObject(_.omit(operand, _.keys(LOGICAL_OPERATORS)), true)) {                               // 686
          subMatcher = compileValueSelector(operand, matcher);                                                  // 687
          isDocMatcher = false;                                                                                 // 688
        } else {                                                                                                // 689
          // This is NOT the same as compileValueSelector(operand), and not just                                // 690
          // because of the slightly different calling convention.                                              // 691
          // {$elemMatch: {x: 3}} means "an element has a field x:3", not                                       // 692
          // "consists only of a field x:3". Also, regexps and sub-$ are allowed.                               // 693
          subMatcher = compileDocumentSelector(operand, matcher,                                                // 694
                                               {inElemMatch: true});                                            // 695
          isDocMatcher = true;                                                                                  // 696
        }                                                                                                       // 697
                                                                                                                // 698
        return function (value) {                                                                               // 699
          if (!isArray(value))                                                                                  // 700
            return false;                                                                                       // 701
          for (var i = 0; i < value.length; ++i) {                                                              // 702
            var arrayElement = value[i];                                                                        // 703
            var arg;                                                                                            // 704
            if (isDocMatcher) {                                                                                 // 705
              // We can only match {$elemMatch: {b: 3}} against objects.                                        // 706
              // (We can also match against arrays, if there's numeric indices,                                 // 707
              // eg {$elemMatch: {'0.b': 3}} or {$elemMatch: {0: 3}}.)                                          // 708
              if (!isPlainObject(arrayElement) && !isArray(arrayElement))                                       // 709
                return false;                                                                                   // 710
              arg = arrayElement;                                                                               // 711
            } else {                                                                                            // 712
              // dontIterate ensures that {a: {$elemMatch: {$gt: 5}}} matches                                   // 713
              // {a: [8]} but not {a: [[8]]}                                                                    // 714
              arg = [{value: arrayElement, dontIterate: true}];                                                 // 715
            }                                                                                                   // 716
            // XXX support $near in $elemMatch by propagating $distance?                                        // 717
            if (subMatcher(arg).result)                                                                         // 718
              return i;   // specially understood to mean "use as arrayIndices"                                 // 719
          }                                                                                                     // 720
          return false;                                                                                         // 721
        };                                                                                                      // 722
      }