Turistforeningen / node-mongo-querystring

Query builder for accepting URL query parameters into your MongoDB queries. Safe and feature rich. Supports most of MongoDB's query operators such as $eq, $gt, $lt, $ne, $in, $nin, $exists, $regex, geospatial queries such as bbox and near, as well as your own custom query business logic!
MIT License
100 stars 31 forks source link

Better examples #2

Closed brianjd closed 8 years ago

brianjd commented 8 years ago

Better examples are needed, preferably a complete scenario.

Starefossen commented 8 years ago

Good suggestion @brianjd, this project should be better documented. In the mean time, you could look at the test suite and the project which this library was initially created for: https://github.com/Turistforeningen/Turbasen/blob/master/coffee/collection.litcoffee

brianjd commented 8 years ago

@Starefossen Thanks,that's exactly what I did to figure out how to use the built-in custom queries (ie. bbox). I will checkout the other project as well. When I have a few more free cycles, I will also try my hand at documentation. Also maybe add some additional 'built-ins'.

Starefossen commented 8 years ago

Here are is a list of all the supported operators:

operation query string query object
equal ?foo=bar { foo: "bar" }
unequal ?foo=!bar { foo: { $ne: "bar" }}
exists ?foo= { foo: { $exists: true }}
not exists ?foo=! { foo: { $exists: false }}
greater than ?foo=>10 { foo: { $gt: 10 }}
less than ?foo=<10 { foo: { $lt: 10 }}
starts with ?foo=^bar { foo: { $regex: "^foo", $options: "i" }}
ends with ?foo=$bar { foo: { $regex: "foo$", $options: "i" }}
contains ?foo=~bar { foo: { $regex: "foo", $options: "i" }}
bbox ?bbox=~0,1,2,3 { geojson: { $geoWithin: { $geometry: { … } } } }
near ?near=~0,1 { geojson: { $near: { $geometry: { … } } } }
after ?after=1388534400 { endret: { $gte: "2014-01-01T00:00:00.000Z" } }
Starefossen commented 8 years ago

I have added this list to README, feel free to open this issue if you feel more examples are necessary.

Starefossen commented 8 years ago

@brianjd just a heads up, I have now added a propper example application: https://github.com/Turistforeningen/node-mongo-querystring/blob/master/examples/app.js