Ravendb 4 - Create Index Programmatically

112 views Asked by At

How to add a index to specific database in RavenDb 4. I see the function

new SearchableIndex().Execute(_documentStore);

How to specify the database, without setting the default database as part of document store initialization. I wish to pass the database name as parameter.

1

There are 1 answers

0
Andrej Krivulčík On

You set the database for the DocumentStore using the Database property. When initializing, do it like this:

var _documentStore = new DocumentStore
{
    Urls = new[] { "http://localhost:8080" },
    Database = "databaseName"
};

new SearchableIndex().Execute(_documentStore);