Hi mates,
I've been looking for current support on Eve for query collections using mongo db where syntax.
It seemed to be fine until I found a couple of problems using queries with dates and ids. I'm gonna focus with dates but it is the same for ObjectIds
The next programatic way to run a query by date looks to be wrong:
>>> q = """{"_created":{"$gte":"2014-12-01"}}"""
>>> len(r.json()["_items"]
0
Actually, when I tried to make a request using a ISODate it returns a 400 code error:
>>> import requests
>>> q = """{"_created":{"$gte":ISODate("2014-12-01")}}"""
It looks to be right, current ISODate is not a right valid field type/syntax for default json module.
>>> json.loads("""{"_created":{"$gte":ISODate("0")}}""")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
But defintly it can be executed under mongo console:
$ mongo
> use mydb
> db.resource.find({"_created": {"$gte":ISODate("2014-12-01")}})
> .....lots of results
It looks to come from how Eve is dealing with json serialization.
Eve uses pymongo when _created and _updated field are created and these fields have to be encoded, but It uses default Json module to encode where parameters, and it has no support for these kind of fields.
Also Eve uses flask jsonify function for encode, and this encode has encoder to give support for date time objects.
Anyone else has encountered these problems? Any ideas to deal with this ?
Thanks.