xaml
xaml

Reputation: 192

How to get list of all collections in RavenDB 4

There was this approach in previous versions -

var terms = new GetTermsOperation("Raven/DocumentsByEntityName", "Tag", "", 1024);

But now it doesn't work. I tried to use another command:

var op = new GetCollectionStatisticsOperation();
var collectionStats = store.Maintenance.Send(op);

But it throws an error - System.ArgumentNullException: 'Value cannot be null. Parameter name: key'

Then i found out how to get the all collections from the browser admin panel:

from @all_docs select distinct @metadata.@collection

How to translate that snippet to c# code?

Upvotes: 1

Views: 383

Answers (2)

Ayende Rahien
Ayende Rahien

Reputation: 22956

If you don't have a database assigned at the document store level, you need to specify it explicitly, like so:

var collectionStats = store.Maintenance.ForDatabase("db-name").Send(op);

Upvotes: 3

xaml
xaml

Reputation: 192

I found a clue - my DocumentStore variable didn't had an assigned Database ( it was assigned in OpenSession constructor):

//Wrong variant
IDocumentStore store = new DocumentStore()
{
    Urls = new string[] { Host }, /*Database = "testdb"*/
}

using (IDocumentSession session = store.OpenSession(dbName))
{
    //some code
}



//Good variant
IDocumentStore store = new DocumentStore()
{
     Urls = new string[] { Host }, Database = "testdb"
}

using (IDocumentSession session = store.OpenSession())
{
     //some code
}

Upvotes: 0

Related Questions