code: function unexpandEntity(sourceObject, includeFields) {
    _.each(sourceObject.links || [], (val, key) => {
      if (!_.isArray(sourceObject.links[key])) {
        // I know the extra .toString seems unnecessary, but sometimes val.id is already an objectId, and other times its
        // a string.
        sourceObject.links[key] = val.id && val.id.toString() || val && val.toString && val.toString();
      } else {
        _.each(sourceObject.links[key], (innerVal, innerKey) => {
          sourceObject.links[key][innerKey] = innerVal.id.toString();
        });
      }
    });
  
    return (includeFields && includeFields.length) ? Util.includeFields(sourceObject, includeFields) : sourceObject;
  }
docs: Transforms an expanded ES source object to an unexpanded object