I often see people ask “how can I delete all documents?” or “how can I delete all documents of type Foo?” this post is mainly so I can paste a link to it for those who keep asking me.
Use the RavenDB Management studio:
Deleting a whole collection:
Introduced in the newer versions of RavenDB, a little right click feature allows you to quickly delete all the documents in a collection.
Deleting multiple documents:
Delete the Hilo document:
After deleting a collection the “hilo” document still exists, this controls the ID for that type of document, so if you want to say add new documents and have the ID’s start at 1, delete this document. You can do it quickly via the “edit document by ID”.
If you find yourself having to repeatedly delete collections for testing, often the best approach is to automate this task. You can use the “DeleteByIndex” feature to use an index and query to select the documents to delete.
For example, if I wanted to use an index to delete all my “enquiry” type documents:
and to also delete the Hilo document so ID numbering resets:
If you want to wipe all your RavenDB data you can just delete the data folder.
If you want to keep deleting it for testing, consider running RavenDB in memory mode, then you just have to enter the reset command and all the data is wiped as you are only storing it in memory.