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

Add support for boolean operator #9

Closed ianjennings closed 8 years ago

ianjennings commented 8 years ago

During development I found that "true" and "false" are always converted into strings, leaving no ability to compare against booleans.

This patch adds support for bools through the : operator.

EX:

?param=:true
Starefossen commented 8 years ago

Thanks for the pull request @ianjennings and sorry for the late response!

I am tempted to propose that this should be done by default? We already parses numbers, I think that "true" and "false" string values should be parsed to true and false boolean values by default. What do you think?

ianjennings commented 8 years ago

From a usability standpoint, that's what I expected from the library. It wasn't until I echo'd the generated query that I saw bool values interpreted as a string.

:+1: I vote to parse booleans by default.

Starefossen commented 8 years ago

Boolean parsing has been implemented by #11 and released in v2.0.0 :rocket: