mongo-filter-query
v1.0.0
Published
A library that simplifies the generation of MongoDB query strings for filtering purposes.
Downloads
19
Readme
mongo-filter-query
A library that simplifies the generation of MongoDB query strings for filtering purposes.
Features
- Generate MongoDB query strings to allow HTTP calls filtering
- No MongoDB skills are necessary at all
Installation
Using NPM:
npm install mongo-filter-query
Basic usage
Import package:
import { Query } from 'mongo-filter-query';
To generate a query to filter for people named "John" who are 25 to 40 years old and who own a Ford or Toyota car:
const query = new Query();
query.addEqualsFilter('name', 'John');
query.addInRangeFilter('age', 25, 40);
query.addMultiSelectFilter('car', ['Ford', 'Toyota']);
console.log(query.toQueryString());
Output will be:
{"$and":[{"name":"John"},{"age":{"$gte":25,"$lte":40}},{"$or":[{"car":"Ford"},{"car":"Toyota"}]}]}