mongo.js
function(obj) {
    _.forEach(obj, function(val, key) {
      if (val && _.isFunction(val.toHexString)) {
        obj[key] = val.toHexString();
      } else if (_.isDate(val)) {
        obj[key] = val;
      } else if (_.isObject(val)) {
        if (val['$oid']) {
          obj[key] = val['$oid'];
        } else {
          obj[key] = this.uncast(val);
        }
      }
    }.bind(this));

    return obj;
  }
function(obj) {
    _.forEach(obj, function(val, key) {
      if (val && _.isFunction(val.toHexString)) {
        obj[key] = val.toHexString();
      } else if (_.isDate(val)) {
        obj[key] = val;
      } else if (_.isObject(val)) {
        if (val['$oid']) {
          obj[key] = val['$oid'];
        } else {
          obj[key] = this.uncast(val);
        }
      }
    }.bind(this));

    return obj;
  }
function ( obj ) { _ . forEach ( obj , function ( val , key ) { if ( val && _ . isFunction ( val . toHexString ) ) { obj [ key ] = val . toHexString ( ) ; } else if ( _ . isDate ( val ) ) { obj [ key ] = val ; } else if ( _ . isObject ( val ) ) { if ( val [ '$oid' ] ) { obj [ key ] = val [ '$oid' ] ; } else { obj [ key ] = this . uncast ( val ) ; } } } . bind ( this ) ) ; return obj ; }
Automatically uncast ObjectId to HexString Will mutate the original object obj can be an object or an array
Automatically uncast ObjectId to HexString Will mutate the original object obj can be an object or an array