The simplest way would be to just delete and then recreate the database. Otherwise you can query all document IDs and purge them. You'd do this for all the documents in a collection. So if you're using collections other than the default, you'd do this for each of them. Doing this in a transaction is quickest.
database.inBatch {
QueryBuilder.select(SelectResult.expression(Meta.id))
.from(DataSource.collection(collection))
.execute().use { rs ->
rs.forEach { result ->
result.getString(0)?.let { id ->
collection.purge(id)
}
}
}
}
Or with the KTX query extensions:
database.inBatch {
select(Meta.id)
.from(collection)
.execute().use { rs ->
rs.forEach { result ->
result.getString(0)?.let { id ->
collection.purge(id)
}
}
}
}
Note the difference between
purge and
delete, where delete preserves a tombstone for syncing the deletion, if you're replicating data with a backend. Purge simply purges the document entirely.