How can I drop a database in PouchDB to get the space on the disk free again?
Remove only sets a paramter _deleted and keeps the Data of the record anyway.
But how can I delete records in a way that actually gets rid of them and saves up some space?
Because I'd like to reset the database every now and then so it doesn't get too big.
Asked
Active
Viewed 5,154 times
3

user2741831
- 2,120
- 2
- 22
- 43
2 Answers
7
It sounds like you are looking for compaction. It will do exactly what you describe. :)

nlawson
- 11,510
- 4
- 40
- 50
-
It says that destroy is deprecated, so should just delete all entrys and then compact the database instead? – user2741831 Feb 20 '15 at 16:03
-
`destroy()` is a separate operation from compaction, and it's `PouchDB.destroy()` that's deprecated, not `db.destroy()`. I'll update the docs to make that clearer. It really depends on what you're trying to achieve. In general, I'd recommend avoiding `destroy()` and using `compact()`, because `destroy()` tends to create some instability in IndexedDB (we're working on that, though). – nlawson Feb 20 '15 at 16:12
-
Thx, I accidentally asked you twice on different threads btw, sorry about – user2741831 Feb 20 '15 at 16:24
6
You can destroy the database and create it again.
var _db = new PouchDB('foo');
var reset = function() {
_db.destroy().then(function() {
_db = new PouchDB('foo');
});
};

mrded
- 4,674
- 2
- 34
- 36