delete all documents in a particular database

867 views
Skip to first unread message

Jeff

unread,
Oct 28, 2012, 1:11:14 PM10/28/12
to rav...@googlegroups.com
I am constantly need to clear a database and import record for testing. I am using smuggler.exe to do the import. however not sure how to delete all documents in a particular database in command line. 

Searched online and find this http://vpetroff.blogspot.com/2012/04/deleting-all-documents-in-ravendb.html. Not sure if this is just for a particular database? can how can I call deletebyindex from command line (dos batch file)?

Thanks. 

Kijana Woodard

unread,
Oct 28, 2012, 1:12:34 PM10/28/12
to rav...@googlegroups.com

For testing...can you just delete the data files.

Kijana Woodard

unread,
Oct 28, 2012, 1:13:05 PM10/28/12
to rav...@googlegroups.com

Meant ?, not .

Oren Eini (Ayende Rahien)

unread,
Oct 28, 2012, 1:14:20 PM10/28/12
to rav...@googlegroups.com
If you want to call it from the command line, you need to do it using curl, see the docs here:

Jeff

unread,
Oct 28, 2012, 1:31:18 PM10/28/12
to rav...@googlegroups.com
there are other dbs there and I don't want to affect them.
in order to do this, need to stop the service, delete specific files(which files??), then restart the service.

Jeff

unread,
Oct 28, 2012, 1:33:29 PM10/28/12
to rav...@googlegroups.com
I see. so I need to define an index which return all docs in that database, then call the set delete method on that index. 

will try this out.

Oren Eini (Ayende Rahien)

unread,
Oct 28, 2012, 1:33:48 PM10/28/12
to rav...@googlegroups.com
DE:ETE /admin/datanases/db_name?hard-delete=true 

Jeff

unread,
Oct 28, 2012, 2:28:03 PM10/28/12
to rav...@googlegroups.com
I am still running stable build 888, is the 'hard-delete' in newer build?

Oren Eini (Ayende Rahien)

unread,
Oct 28, 2012, 3:03:19 PM10/28/12
to rav...@googlegroups.com
Yes, 1.2 

Jeff

unread,
Oct 28, 2012, 3:20:56 PM10/28/12
to rav...@googlegroups.com
what's the exactly syntax for the curl call?

I defined index "AllDocumentsByID", then tried following curl


but this command deleted the index "AllDocumentsByID" iself, not the documents returned by the index.

Kijana Woodard

unread,
Oct 28, 2012, 3:22:26 PM10/28/12
to rav...@googlegroups.com

IIRC the data is in the tenants folder. So you can delete the unwanted db that way.

Jeff

unread,
Oct 28, 2012, 4:14:37 PM10/28/12
to rav...@googlegroups.com
Kijana,

that should works: stop service, delete folder, re-start service. and re-start the web asp.net app, so those index can re-populate...

it is just not that neat, all i want to do is delete documents, indexes and web app shouldn't be touched at all. 

bulk delete by index AllDocumentId should work, just need to figure out exact syntax.

Thanks.

Justin A

unread,
Oct 29, 2012, 1:40:02 AM10/29/12
to rav...@googlegroups.com
DELETE /admin/datanases/db_name?hard-delete=true 

Oh awesome! this will come in handy for things like RavenHQ (free) where we have a limited number of HD space.

is there an API for this? sesson.Advanced.DeleteAllTheThings("myTenant"); ?

Oren Eini (Ayende Rahien)

unread,
Oct 29, 2012, 3:46:59 AM10/29/12
to rav...@googlegroups.com
There isn't an API for that, but you can use:

But you can do:

var relativeUrl = "/admin/databases/" + databasesModel.SelectedDatabase.Name;
if (deleteDatabase.hardDelete.IsChecked == true)
relativeUrl += "?hard-delete=true";
var httpJsonRequest = asyncDatabaseCommands.CreateRequest(relativeUrl, "DELETE");
httpJsonRequest.ExecuteRequestAsync()


Note that this requires you to be admin.

Chris Marisic

unread,
Oct 30, 2012, 10:45:02 AM10/30/12
to rav...@googlegroups.com
You want Delete By Index, not delete index. There should be info on the http api docs.

My biggest fucked up with RavenDB was I once accidentally did delete by index, instead of delete index. That was a long long night recovering from that mistake.

Matt Warren

unread,
Oct 30, 2012, 10:46:31 AM10/30/12
to rav...@googlegroups.com
> My biggest fucked up with RavenDB was I once accidentally did delete by index, instead of delete index. That was a long long 
> night recovering from that mistake. 

Ouch!!!!

Jeff

unread,
Oct 30, 2012, 11:18:45 AM10/30/12
to rav...@googlegroups.com
I read the doc online in this page http://ravendb.net/docs/http-api/http-api-multi


I guess this is target to the default database. how do I do on a particular database? also in my case, there is no query. what's the syntax will be?

Thanks.

Oren Eini (Ayende Rahien)

unread,
Oct 31, 2012, 9:24:55 AM10/31/12
to rav...@googlegroups.com

Oren Eini (Ayende Rahien)

unread,
Oct 31, 2012, 9:27:06 AM10/31/12
to rav...@googlegroups.com
With no query, you do something like:

DELETE http://localhost:8080/databases/your_db/bulk_docs/Raven/DocumentsByEntityName
Reply all
Reply to author
Forward
0 new messages