diegohaz/querymen

Optional sort param

chemitaxis opened this issue · 0 comments

Hi @diegohaz, I'm thinking about mandatory sort. We are working with MongoDb, and some querys we don't need an index for sorting, but the "sort" param is always "one" because we have a default value:

sort: {
        type: [String],
        default: '-createdAt',
        bindTo: 'cursor',
        parse: (value) => {
          let fields = _.isArray(value) ? value : [value]
          let sort = {}
          fields.forEach((field) => {
            if (field.charAt(0) === '-') {
              sort[field.slice(1)] = -1
            } else if (field.charAt(0) === '+') {
              sort[field.slice(1)] = 1
            } else {
              sort[field] = 1
            }
          })
          return {sort: sort}
        }
      }

Can you please give some "light" to try this sort param in the Schema as "optional". Thanks!