I am working on integration test. As we are using NServiceBus Saga with ravendb as store, for integration test I need to delete all documents in raven store for each test case. Since this a NServiceBus saga store, document type in Raven Db is not known in integration test. Basically I need to read all documents (any type) and delete them. I am looking forward to write a query in ravendb session, to retrieve all documents from a particular database. When I checked the Raven Db Query method, it expect Type of the document. Whereas I need to query all the documents in the database without type. FYI as this the integration test, raven store will not have many records. So performance is not an issue.
Here is the query I am trying to execute.
"from doc in docs let DocId = doc[\"@metadata\"][\"@id\"] select new {DocId};"
Solution 1 :
I also tried to create index for the above query and executed DeleteByIndex. This actually deletes all the documents in the database. But it works for certain test cases and throw exception in another test case saying that "Stale Index". I also found a solution that code could wait until index is completed to avoid the stale exception. Or set allowstale to true to avoid this exception. I thought that instead going through all indexing stuff, why can't I just write a query to retrieve all documents and delete them.
Solution 2: I found an another solution that delete the ravendb document folder. This will not work for my situation, because NServices bus will throw exception if database is deleted while NServiceBus windows processor running. That breaks our integration test cases. Another reason that integration test will be running in different machine than ravendb machine. So integration test box may not have access to ravendb box's folder.
These are all the reasons I am looking to write a query to fetch all documents from the database and delete them.
Any help is appreciated.