I am submitting a pretty simple query to MongoDB (version 2.6) using the pymongo library for python:
query = {"type": "prime"}
logging.info("Querying the DB")
docs = usaspending.get_records_from_db(query)
logging.info("Done querying. Sorting the results")
docs.sort("timestamp", pymongo.ASCENDING)
logging.info("Done sorting the results, getting count")
count = docs.count(True)
logging.info("Done counting: %s records", count)
pprint(docs[0])
raise Exception("End the script right here")
The get_records_from_db()
function is quite simple:
def get_records_from_db(query=None):
return db.raws.find(query, batch_size=50)
Note that I will actually need to work with all the documents, not just docs[0]
. I am just trying to get docs[0]
as an example.
When I run this query the output I get is:
2015-01-28 10:11:05,945 Querying the DB
2015-01-28 10:11:05,946 Done querying. Sorting the results
2015-01-28 10:11:05,946 Done sorting the results, getting count
2015-01-28 10:11:06,617 Done counting: 559952 records
However I never get back docs[0]
. I have an indexes on {"timestamp": 1}
and {"type": 1}
, and queries seem to work reasonably well (as the count is returned quite fast), but I am not sure why I never get back the actual document (the docs are quite small [under 50K]).