code: function setOptions(schema, options) {
    function setDefaults(array) {
      if (!array.length) {
        if (options.find) { array.push('find'); }
        if (options.findOne || !options.find) { array.push('findOne'); }
      }
    }
  
    options = options || {};
  
    options.only = options.only || [];
    options.validateBeforeSave = options.validateBeforeSave === undefined
                                  ? schema.options.validateBeforeSave
                                  : Boolean(options.validateBeforeSave);
  
    ['virtual', 'attach', 'modify'].filter(prop => options[prop])
      .forEach(
        prop => {
          if (typeof options[prop] !== 'object') {
            options[prop] = {};
          }
          options[prop].properties = options[prop].properties || {};
          options[prop].only = options[prop].only || Object.keys(options[prop].properties);
        }
      );
  
    if (options.modify) {
      delete options.modify.properties;
      options.modify.on = options.modify.on || [];
      setDefaults(options.modify.on);
    }
    if (options.attach) {
      Object.keys(options.attach.properties).forEach(property => {
        options.attach.properties[property].on = options.attach.properties[property].on || [];
        setDefaults(options.attach.properties[property].on);
      });
    }
  
    return options;
  }
docs: Setup options and defaults