I went through many cursor iterationn questions, but saw nothing which can solve my problem.
I have a database of the form
[{book:'A', author:'John'}, {book:'B', author:'Tony'}, {book:'C', author:'John'}...]
Multiple books for same author possible.
What I need is 2 arrays
authors = ['John','Tony','John']
books = ['A','B','C']
where corresponding elements falls at same index in both arrays.
Now I am getting it by cursor iteration.
authors =[]
books =[]
cursor = collection.find()
for elem in cursor:
authors.append(elem['author'])
books.append(elem['book'])
But this is very slow. I have thousands of documents. Are there any other ways like queries to achieve the result faster.