Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question, Help needed] AND operator #60

Open
awojtczyk opened this issue Nov 26, 2017 · 2 comments
Open

[Question, Help needed] AND operator #60

awojtczyk opened this issue Nov 26, 2017 · 2 comments

Comments

@awojtczyk
Copy link

awojtczyk commented Nov 26, 2017

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.

@HugoLiconV
Copy link

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.

@wesias7
Copy link

wesias7 commented Aug 28, 2018

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants