SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

Search document by date using collection filter #38

Closed djaswal closed 9 years ago

djaswal commented 9 years ago

Hey, I was wondering if its possible to search the document using date (iso string or epoch time) through uri?

example: http://somedomain.com/somecollection?filter={'date':'1436911606420'}

Thanks,

ujibang commented 9 years ago

Sure you can!

The filter query parameter can be any mongodb query using any operator.

For instance you can do the following for a range date filter:

http://somedomain.com/somecollection?filter="{'$and':[{'date':{'$gte':'1436911606420'}},{'date':{'$lte':'1436921606420'}}]}"

Note also that mongodb data format is bson, which includes a date type. In this case you do:

{'date': { "$date": "" }}

is an ISO-8601 date format with a mandatory time zone field following the template YYYY-MM-DDTHH:mm:ss.mmm<+/-Offset>. See http://restheart.org/docs/resource-representation-format.html for more info.