(pouchdb/pouchdb#2818) - read keys into memory

Reading the keys into memory before starting iteration fixes all the tests in pouchdb/pouchdb#2818. It also makes the code simpler; look at all those deletions.