querymen icon indicating copy to clipboard operation
querymen copied to clipboard

[Question, Help needed] AND operator

Open awojtczyk opened this issue 8 years ago • 2 comments

Hello, Is it possible, to have something like this:

query({
    attractions: { type: [String], paths: ['attractions'], multiple: true },
    categories: { type: [String], paths: ['category'], multiple: true },
    search: {
      type: RegExp,
      paths: ['name', 'description', 'city', 'street']
    }
  }),

And that would I like to have, is to match all of the rules, for example, if attractions and categories are specified, I'd like to have only objects which match both of the rules.

Same for search functionality, both filters should be applied (attractions and categories), then the search regex.

awojtczyk avatar Nov 26 '17 18:11 awojtczyk

I have the same question, I need it to obtain documents between certain dates. I did this but it didn't work:

after: {
      type: Date,
      paths: ['fecha'],
      operator: '$gte'
},
before: {
      type: Date,
      paths: ['fecha'],
      operator: '$lte'
}

I really need to use AND Operator.

HugoLiconV avatar Aug 06 '18 04:08 HugoLiconV

i have the same question. i try it.

first, querymen schema setup before express router code.

import { Schema as QuerymenSchema } from 'querymen'

const qms = new QuerymenSchema({
  createdAtDate: { type: Date, paths: ['createdAt'], duration: 'date', },
})

qms.parser('duration', (duration, value, path, operator) => {
  if (!value) { return value }
  if (duration == 'date') { 
    value = { [path]: { '$gte': new Date(value.setHours(0,0,0,0)), '$lte': new Date(value.setHours(23,59,59,999)), } }
  }
  return value
})

then, you try router setup.

router.get('/',
  query(querySchema),
  index)

that's easy? (always, Diegohaz is great. greatness.)

wesias7 avatar Aug 28 '18 07:08 wesias7