删除未找到RavenDB中的索引

时间:2012-08-07 13:40:36

标签: ravendb

我正在尝试为多租户ravendb编写一个通用删除函数,用于集成测试该类是 -

public class RavenDeleteAll
{
    private readonly IDocumentStore _store;
    private readonly string _testDataBase;

    public RavenDeleteAll(string testDataBase, IDocumentStore store)
    {
        _testDataBase = testDataBase;
        _store = store;
    }

    public void Clear<T>(string indexName)
    {
        using (var session = _store.OpenSession(_testDataBase))
        {
            session.Advanced.DocumentStore.DatabaseCommands.DeleteIndex(indexName);

            session.Advanced.DocumentStore.DatabaseCommands.PutIndex(indexName, new IndexDefinitionBuilder<T>
                                                                                        {
                                                                                            Map = documents => documents.Select(entity => new { })
                                                                                        });
            var indexDefinition = session.Advanced.DocumentStore.DatabaseCommands.GetIndex(indexName);
            session.Advanced.LuceneQuery<T>(indexName)
           .WaitForNonStaleResultsAsOfNow()
           .Take(0)
           .ToList();

            session.Advanced.DatabaseCommands.DeleteByIndex(indexName, new IndexQuery());


        }

    }
}

请注意,在代码中我尝试在putindex调用之后读回索引以进行健全性检查。但是当我执行索引时,会抛出一个invalidoperationexception,指出/ indexes / UTO不存在?

同样从管理控制台我可以清楚地看到索引 -  enter image description here

我不做什么?索引是在默认数据库下创建的,而不是实际的数据库名称?

1 个答案:

答案 0 :(得分:2)

看起来您正在默认数据库而不是租户数据库中创建索引,然后向租户数据库询问该索引。您需要在要使用它的数据库中创建索引。以下内容未经过测试,但可用于在租户数据库中创建索引。

IDatabaseCommands context = session.Advanced.DocumentStore.DatabaseCommands.ForDatabase(database);
context.PutIndex(indexName, new IndexDefinitionBuilder<T>
    {
        Map = documents => documents.Select(entity => new { })
    });
相关问题