meteor/minimongo/selector.js
function (selector) {
    var self = this;
    // you can pass a literal function instead of a selector
    if (_.isFunction(selector)) {
      self._isSimple = false;
      self._selector = selector;
      self._recordPathUsed('');
      return function (doc) {
        return {result: !!selector.call(doc)};
      };
    }

    // shorthand -- scalars match _id
    if (LocalCollection._selectorIsId(selector)) {
      self._selector = {_id: selector};
      self._recordPathUsed('_id');
      return function (doc) {
        return {result: EJSON.equals(doc._id, selector)};
      };
    }

    // protect against dangerous selectors.  falsey and {_id: falsey} are both
    // likely programmer error, and not what you want, particularly for
    // destructive operations.
    if (!selector || (('_id' in selector) && !selector._id)) {
      self._isSimple = false;
      return nothingMatcher;
    }

    // Top level can't be an array or true or binary.
    if (typeof(selector) === 'boolean' || isArray(selector) ||
        EJSON.isBinary(selector))
      throw new Error("Invalid selector: " + selector);

    self._selector = EJSON.clone(selector);
    return compileDocumentSelector(selector, self, {isRoot: true});
  }
function (selector) {
    var self = this;
    // you can pass a literal function instead of a selector
    if (_.isFunction(selector)) {
      self._isSimple = false;
      self._selector = selector;
      self._recordPathUsed('');
      return function (doc) {
        return {result: !!selector.call(doc)};
      };
    }

    // shorthand -- scalars match _id
    if (LocalCollection._selectorIsId(selector)) {
      self._selector = {_id: selector};
      self._recordPathUsed('_id');
      return function (doc) {
        return {result: EJSON.equals(doc._id, selector)};
      };
    }

    // protect against dangerous selectors.  falsey and {_id: falsey} are both
    // likely programmer error, and not what you want, particularly for
    // destructive operations.
    if (!selector || (('_id' in selector) && !selector._id)) {
      self._isSimple = false;
      return nothingMatcher;
    }

    // Top level can't be an array or true or binary.
    if (typeof(selector) === 'boolean' || isArray(selector) ||
        EJSON.isBinary(selector))
      throw new Error("Invalid selector: " + selector);

    self._selector = EJSON.clone(selector);
    return compileDocumentSelector(selector, self, {isRoot: true});
  }
function ( selector ) { var self = this ; // you can pass a literal function instead of a selector if ( _ . isFunction ( selector ) ) { self . _isSimple = false ; self . _selector = selector ; self . _recordPathUsed ( '' ) ; return function ( doc ) { return { result : ! ! selector . call ( doc ) } ; } ; } // shorthand -- scalars match _id if ( LocalCollection . _selectorIsId ( selector ) ) { self . _selector = { _id : selector } ; self . _recordPathUsed ( '_id' ) ; return function ( doc ) { return { result : EJSON . equals ( doc . _id , selector ) } ; } ; } // protect against dangerous selectors.  falsey and {_id: falsey} are both // likely programmer error, and not what you want, particularly for // destructive operations. if ( ! selector || ( ( '_id' in selector ) && ! selector . _id ) ) { self . _isSimple = false ; return nothingMatcher ; } // Top level can't be an array or true or binary. if ( typeof ( selector ) === 'boolean' || isArray ( selector ) || EJSON . isBinary ( selector ) ) throw new Error ( "Invalid selector: " + selector ) ; self . _selector = EJSON . clone ( selector ) ; return compileDocumentSelector ( selector , self , { isRoot : true } ) ; }
Given a selector, return a function that takes one argument, a document. It returns a result object.
Given a selector return a function that takes one argument a document . It returns a result object .