mongo.js
function(obj) {
    _.forEach(obj, function(val, key) {
      if (_.isString(val)) {
        if (Mixins.isObjectId(val)) {
          obj[key] = Mixins.newObjectId(val);
        } else if (Mixins.isValidISO8601String(val)) {
          obj[key] = new Date(val);
        }
      } else if (_.isDate(val)) {
        obj[key] = val;
      } else if (_.isObject(val)) {
        if (val['$oid']) {
          obj[key] = val['$oid'];
        } else {
          obj[key] = this.cast(val);
        }
      }
    }.bind(this));

    return obj;
  }
function(obj) {
    _.forEach(obj, function(val, key) {
      if (_.isString(val)) {
        if (Mixins.isObjectId(val)) {
          obj[key] = Mixins.newObjectId(val);
        } else if (Mixins.isValidISO8601String(val)) {
          obj[key] = new Date(val);
        }
      } else if (_.isDate(val)) {
        obj[key] = val;
      } else if (_.isObject(val)) {
        if (val['$oid']) {
          obj[key] = val['$oid'];
        } else {
          obj[key] = this.cast(val);
        }
      }
    }.bind(this));

    return obj;
  }
function ( obj ) { _ . forEach ( obj , function ( val , key ) { if ( _ . isString ( val ) ) { if ( Mixins . isObjectId ( val ) ) { obj [ key ] = Mixins . newObjectId ( val ) ; } else if ( Mixins . isValidISO8601String ( val ) ) { obj [ key ] = new Date ( val ) ; } } else if ( _ . isDate ( val ) ) { obj [ key ] = val ; } else if ( _ . isObject ( val ) ) { if ( val [ '$oid' ] ) { obj [ key ] = val [ '$oid' ] ; } else { obj [ key ] = this . cast ( val ) ; } } } . bind ( this ) ) ; return obj ; }
Automatically cast to HexString to ObjectId Automatically cast ISO8601 date strings to Javascript Date Will mutate the original object obj can be an object or an array
Automatically cast to HexString to ObjectId Automatically cast ISO8601 date strings to Javascript Date Will mutate the original object obj can be an object or an array