Reputation: 279
I want to repeatedly create and delete a PouchDB database with the same name ('Test') during my unit tests. But if I add at least one document to the database before deleting it, then the next time I try to create it I get the error:
"Uncaught NotFoundError: Failed to execute 'objectStore' on 'IDBTransaction': The specified object store was not found."
This happens at pouchdb.js:1950:
var docStore = transaction.objectStore(DOC_STORE); // PouchDB 3.0.6
Then if I look at IndexedDB, the DB does exist but only with the following info:
Security origin:http://localhost:8000
Name:_pouch_Test
Integer Version:1
String Version:
Then if I try to delete this DB, Angular throws a 'CustomPouchError', which I haven't traced through.
Here are the relevant code snippets from my app:
var db = new PouchDB(dbName, function(err, result) {
if (!err) {
$log.info('Database \'' + dbName + '\' opened'); // Happens when I first create 'Test'
} else {
$log.info('Database \'' + dbName + '\' failed to open'); // Happens when I try to re-create 'Test'
}
});
db.destroy(function (err, info) {
if (err) {
$log.error(err);
} else {
$log.info("Database destroyed"); // Happens when I delete 'Test'
}
});
But if I delete the database before adding any documents to it, it disappears from IndexedDB and then I can create it again.
Thanks for your help.
Upvotes: 2
Views: 1215
Reputation: 41
Found a workaround. After destroy, create a new PouchDB object in the "then" function. It works fine next time you use it. Eg.
var db = new PouchDB('Xyz');
db.destroy().then(function (response) {
db = new PouchDB('Xyz');
});
Upvotes: 2