docs: function (a, b) {
      if (a === undefined)
        return b === undefined ? 0 : -1;
      if (b === undefined)
        return 1;
      var ta = LocalCollection._f._type(a);
      var tb = LocalCollection._f._type(b);
      var oa = LocalCollection._f._typeorder(ta);
      var ob = LocalCollection._f._typeorder(tb);
      if (oa !== ob)
        return oa < ob ? -1 : 1;
      if (ta !== tb)
        // XXX need to implement this if we implement Symbol or integers, or
        // Timestamp
        throw Error("Missing type coercion logic in _cmp");
      if (ta === 7) { // ObjectID
        // Convert to string.
        ta = tb = 2;
        a = a.toHexString();
        b = b.toHexString();
      }
      if (ta === 9) { // Date
        // Convert to millis.
        ta = tb = 1;
        a = a.getTime();
        b = b.getTime();
      }
  
      if (ta === 1) // double
        return a - b;
      if (tb === 2) // string
        return a < b ? -1 : (a === b ? 0 : 1);
      if (ta === 3) { // Object
        // this could be much more efficient in the expected case ...
        var to_array = function (obj) {
          var ret = [];
          for (var key in obj) {
            ret.push(key);
            ret.push(obj[key]);
          }
          return ret;
        };
        return LocalCollection._f._cmp(to_array(a), to_array(b));
      }
      if (ta === 4) { // Array
        for (var i = 0; ; i++) {
          if (i === a.length)
            return (i === b.length) ? 0 : -1;
          if (i === b.length)
            return 1;
          var s = LocalCollection._f._cmp(a[i], b[i]);
          if (s !== 0)
            return s;
        }
      }
      if (ta === 5) { // binary
        // Surprisingly, a small binary blob is always less than a large one in
        // Mongo.
        if (a.length !== b.length)
          return a.length - b.length;
        for (i = 0; i < a.length; i++) {
          if (a[i] < b[i])
            return -1;
          if (a[i] > b[i])
            return 1;
        }
        return 0;
      }
      if (ta === 8) { // boolean
        if (a) return b ? 0 : 1;
        return b ? -1 : 0;
      }
      if (ta === 10) // null
        return 0;
      if (ta === 11) // regexp
        throw Error("Sorting not supported on regular expression"); // XXX
      // 13: javascript code
      // 14: symbol
      // 15: javascript code with scope
      // 16: 32-bit integer
      // 17: timestamp
      // 18: 64-bit integer
      // 255: minkey
      // 127: maxkey
      if (ta === 13) // javascript code
        throw Error("Sorting not supported on Javascript code"); // XXX
      throw Error("Unknown type to sort");
    }