When I run the following in the mongodb shell, it returns the correct number of records:
(searching for the matching "SourceName" within the last 8 days)
mongos> db.fdl.count({ SourceName : "SRC1" , "Created" : { $gte : new Date(new Date().setDate(new Date().getDate()-8)) }})
482
But when I try to run it through python / pymongo, it returns nothing:
import time
import pymongo
myclient = pymongo.MongoClient("mongodb://mylogin:mypass@mymongo.mydomain.net")
mydb = myclient['fdl']
print mydb.fdl.count({ SourceName : "SRC1" , "Created" : { $gte : new Date(new Date().setDate(new Date().getDate()-8)) }})
myclient.close()
then run it:
python query.py
0
In the python code, if I run the query:
print mydb.fdl.count({ SourceName : "SRC1" })
Then I do get a value. So the problem comes from the $gte search.
The problem is not with the count() method, because if I use the find() method, the problem is the same: documents returned in the MongoDB shell, but nothing when calling with python.
Any help would be greatly appreciated ! Thanks a lot in advance :-)