code: function(query, model, logger) {
      // This line has to come first
      validationHelper.validateModel(model, logger)
  
      let attributesFilter = []
      let fields = model.schema.paths
      let fieldNames = []
  
      if (query.$select) {
        if (!Array.isArray(query.$select)) {
          query.$select = query.$select.split(',')
        }
        fieldNames = query.$select
      } else {
        fieldNames = Object.keys(fields)
      }
  
      let associations = model.routeOptions
        ? model.routeOptions.associations
        : null
  
      for (let i = 0; i < fieldNames.length; i++) {
        let fieldName = fieldNames[i]
        if (
          fields[fieldName] &&
          fieldName !== '__v' &&
          fieldName.substr(-2) !== '$*'
        ) {
          let field = fields[fieldName].options
          let association = associations
            ? associations[fields[fieldName].path] || {}
            : {}
  
          // EXPL: by default we don't include MANY_MANY array references
          if (
            !field.exclude &&
            (association.type !== 'MANY_MANY' || query.$select)
          ) {
            attributesFilter.push(fieldName)
          }
        }
      }
  
      delete query.$select
      return attributesFilter.toString().replace(/,/g, ' ')
    }
docs: Create a list of selected fields to be returned based on the '$select' query property.
  @param query: The incoming request query.
  @param model: A mongoose model object.
  @param logger: A logging object.
  @returns {string}