apache / apache/pouchdb

"Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing" error when destroying and recreating database

Open
#8,551 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
17.6k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

### Issue
First and foremost, holy crap do I love PouchDB. :-) I'm new to PouchDB but it's making my offline-first app so much easier to build, so thank you for all the excellent work on PouchDB!

Here's my issue: In a Vue 3 + Ionic application, I'm implementing a "Refresh Data" button so the user can essentially start fresh with all new data from the server. For context, this is a one-way sync app where the user will only be pulling data down from a remote server, i.e. nothing ever goes from the local app up to the remote server.

Here's the relevant code for when the user taps the refresh button:
```typescript
import PouchDB from 'pouchdb'

const refreshData = async () => {
let pouchDB = new PouchDB('my-db')
const remoteDB = new PouchDB('https://remote-db-here')

await pouchDB.destroy()
pouchDB = new PouchDB('my-db')

await pouchDB.replicate.from(remoteDB)

// create the necessary indexes -- there's three total, just putting one here
await pouchDB.createIndex({
index: { fields: ['some', 'fields' here']
})
}
```

When that finishes running, I get this error:
`Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.`

And if I start clicking around in the app it continues to throw that error.

As I said I'm new to PouchDB so I may be missing something fundamental, and if this is a "don't do that" situation and I should bulk delete all the docs instead of destroying the db, I'm very open to suggestions. Thanks!

### Info
- Environment: Vue 3.2.36, Ionic Vue 6.3.1, PouchDB 7.3.0
- Platform: Chrome 106.0.5249.119
- Adapter: DIdn't specify in options, so I think that means IndexedDB?
- Server: PouchDB 7.3.0 locally, CouchDB 3.2.2 remote

### Reproduce
See above code

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.