leodinas-hao / mongoose-query-parser

Convert url query string to MongooseJs friendly query object including advanced filtering, sorting, population, string template, type casting and many more...
MIT License
68 stars 17 forks source link

$and operator in query #5

Closed shanmugarajbe closed 5 years ago

shanmugarajbe commented 5 years ago

How to use $and operator in the query parameter? I am currently passing query param as?attrs.value=Festival&attrs.id=44&attrs.value=Cotton, but it is parsed as or by default using $inoperator. How can send in the url in such way that it will be parsed as $and ? I need to get the documents matching both attrs.value conditions.

Thanks

leodinas-hao commented 5 years ago

$and is not supported as an operator. The only way for now is to pass in JSON string. An example is as below:

parser.parse('filter={"$or":[{"key1":"value1"},{"key2":"value2"}]}&name=Telstra');
// {
//   filter: {
//     $or: [
//       { key1: 'value1' },
//       { key2: 'value2' }
//     ],
//     name: 'Telstra'
//   },
// }

It would be really appreciated if you have a PR for supporting $and?