【问题标题】:Deleting All Documents in RavenDB删除 RavenDB 中的所有文档
【发布时间】:2015-04-01 12:32:53
【问题描述】:

关于如何删除 RavenDB 数据库中的所有文档,WWW 上有很多提示。有些比其他的更复杂,即http://vpetroff.blogspot.co.uk/2012/04/deleting-all-documents-in-ravendb.html

【问题讨论】:

    标签: c# ravendb


    【解决方案1】:

    我一直在使用第 3 版,"Auto/AllDocs" 似乎不起作用。但是,您可以检索索引名称并以这种方式删除,例如:

            var indexDefinitions = _documentStore.DatabaseCommands.GetIndexes(0, 100);
            foreach (var indexDefinition in indexDefinitions)
            {
                _documentStore.DatabaseCommands.DeleteByIndex(indexDefinition.Name, new IndexQuery());
            }
    

    【讨论】:

      【解决方案2】:

      使用最新版本的 RavenDB,您可以简单地使用内置的 Auto/AllDocs 索引。

          private static void DeleteFiles(IDocumentStore documentStore)
          {
              var staleIndexesWaitAction = new Action(
                  delegate
                  {
                      while (documentStore.DatabaseCommands.GetStatistics().StaleIndexes.Length != 0)
                      {
                          Thread.Sleep(10);
                      }
                  });
              staleIndexesWaitAction.Invoke();
              documentStore.DatabaseCommands.DeleteByIndex("Auto/AllDocs", new IndexQuery());
              staleIndexesWaitAction.Invoke();
          }
      

      【讨论】:

      • "Auto/AllDocs" 似乎不起作用。 @Seth 的回答对我有用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      相关资源
      最近更新 更多