Currently, I have a mongo document that looks like this:
{'_id': id, 'title': title, 'date': date}
What I'm trying to search by name in this document, in the database I have 5 items that are not many, but my file has 1 million titles to search.
I guarantee the name as an index in the collection, but still the running time is rather slow (about 40 seconds per 1000 names, something obvious, since I am making a request for the title), here is my code:
Creating a job repository:
class WorkRepository(GenericRepository, Repository):
def __init__(self, url_root):
super(WorkRepository, self).__init__(url_root, 'works')
self._db[self.collection].ensure_index('title')
Program input (this is REST api):
start = time.clock()
for work in json_works:
result = work_repository.find_works_by_title(work['title'])
if result:
works[work['id']] = result
end = time.clock()
print end-start
return json_encoder(request, works)
and find_works_by_title:
def find_works_by_title(self, work_title):
works = list(self._db[self.collection].find({'title': work_title}))
return works
I am new to mongo and probably I made some kind of mistake, any recommendation?