RavenDB: Deleting all documents

ASP.NET MVC,RavenDB 20 February 2012 | 2 Comments

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.

ravendb delete a whole collection

Deleting multiple documents:

You can highlight multiple documents as you would files in Windows Explorer and select delete.
ravendb delete 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”.

ravendb delete the hilo document

Using C#:

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:

Delete everything:

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.

2 Responses on “RavenDB: Deleting all documents”

  1. bill says:

    I’m having a hell of a time, I delete the dat folder, studio shows a fresh instance, but as soon as i run code all the data gets re-created…

    Seems like the client is recreating it from cache or something..

  2. Lars says:

    Gist-listings do not work :( Links?

Leave a Reply