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

Not and return #22

Closed simon-p-r closed 8 years ago

simon-p-r commented 8 years ago

Firstly thanks for this great library!

However the only operators I think are missing are the ability to control was it returned, I use the syntax "not" to exclude or "return" to include what fields are returned within document from mongo,

Starefossen commented 8 years ago

Hi @simon-p-r and thanks for the kind words!

Just to make sure I get what you are talking about; projection right?

>db.mycol.find({},{"title":1,_id:0})

{"title":"MongoDB Overview"}
{"title":"NoSQL Overview"}
{"title":"Tutorials Point Overview"}

I am not entirely convinced this is something the mongo-querystring library should do. In any case, this is how I would suggest this feature could look like on the URL query parameter:

?fields=field1&fields=field2&fields=!field3

This should evaluate to the following projection:

{
  "field1": 1,
  "field2": 1,
  "field3": 0
}
simon-p-r commented 8 years ago

Yes projection, the only problem is this module won't return this as a separate object. I will close as I have now found this module which handles this so will close this issue.