当ravendb正在运行托管其他数据库时,删除单个ravendb数据库

时间:2022-06-15 23:25:02

Is there any way I can remove all data in a single database while RavenDB is still running, hosting other databases?

在RavenDB仍在运行,托管其他数据库时,有什么方法可以删除单个数据库中的所有数据?

In a production environment with RavenDB hosting multiple databases for different customers, it is not acceptable to stop RavenDB in order to delete the data from a single database. Would it be necessary to custom develop a tool, at delete documents individually to achieve this?

在RavenDB为不同客户托管多个数据库的生产环境中,停止RavenDB以从单个数据库中删除数据是不可接受的。是否有必要自定义开发工具,单独删除文档来实现这一目标?

3 个解决方案

#1


10  

If you delete the document that describes the database then you have prevented access to it. RavenDB doesn't provide a way to actually delete the database, but the database would be shut down if you delete the document describing it. You can then delete the database directory, or back it up, according to your needs.

如果删除描述数据库的文档,则表示您已禁止访问该文档。 RavenDB没有提供实际删除数据库的方法,但是如果删除描述它的文档,数据库将被关闭。然后,您可以根据需要删除数据库目录或进行备份。

#2


6  

In version 2.0.3 (maybe even in releases before) the studio is calling the following http endpoint in order to delete a database:

在2.0.3版本中(甚至可能在之前的版本中),工作室调用以下http端点以删除数据库:

/admin/databases/nameOfYourDatabase?hard-delete=true
?hard-delete=true is optional.

/ admin / databases / nameOfYourDatabase?hard-delete = true?hard-delete = true是可选的。

Based on the source code from the studio I have created this function:

基于工作室的源代码,我创建了这个函数:

    public void DeleteDatabase(string name, bool hardDelete = false)
    {
        if (string.IsNullOrEmpty(name))
            throw new ArgumentNullException("name");

        var databaseCommands = _documentStore.DatabaseCommands;
        var relativeUrl = "/admin/databases/" + name;

        if (hardDelete)
            relativeUrl += "?hard-delete=true";

        var serverClient = databaseCommands.ForSystemDatabase() as ServerClient;
        if (serverClient == null)
            throw new ApplicationException("Please use a more intelligent exception here");

        var httpJsonRequest = serverClient.CreateRequest("DELETE", relativeUrl);
        httpJsonRequest.ExecuteRequest();
    }

#3


1  

I want to update your solution, that are the only solution for "deleting" a database.

我想更新您的解决方案,这是“删除”数据库的唯一解决方案。

Actually in the new version (2.0) of RavenDB, which are still unstable, you can delete a database with the new version of the studio.

实际上在RavenDB的新版本(2.0)中仍然不稳定,您可以使用新版本的工作室删除数据库。

You can download it from here: http://hibernatingrhinos.com/builds/ravendb-unstable-v2.0/

你可以从这里下载:http://hibernatingrhinos.com/builds/ravendb-unstable-v2.0/

I'll hope this help you aditionally to the Ayende good answer.

我希望这能帮助你顺利完成Ayende的好回答。

Best, Dario

最好,达里奥

#1


10  

If you delete the document that describes the database then you have prevented access to it. RavenDB doesn't provide a way to actually delete the database, but the database would be shut down if you delete the document describing it. You can then delete the database directory, or back it up, according to your needs.

如果删除描述数据库的文档,则表示您已禁止访问该文档。 RavenDB没有提供实际删除数据库的方法,但是如果删除描述它的文档,数据库将被关闭。然后,您可以根据需要删除数据库目录或进行备份。

#2


6  

In version 2.0.3 (maybe even in releases before) the studio is calling the following http endpoint in order to delete a database:

在2.0.3版本中(甚至可能在之前的版本中),工作室调用以下http端点以删除数据库:

/admin/databases/nameOfYourDatabase?hard-delete=true
?hard-delete=true is optional.

/ admin / databases / nameOfYourDatabase?hard-delete = true?hard-delete = true是可选的。

Based on the source code from the studio I have created this function:

基于工作室的源代码,我创建了这个函数:

    public void DeleteDatabase(string name, bool hardDelete = false)
    {
        if (string.IsNullOrEmpty(name))
            throw new ArgumentNullException("name");

        var databaseCommands = _documentStore.DatabaseCommands;
        var relativeUrl = "/admin/databases/" + name;

        if (hardDelete)
            relativeUrl += "?hard-delete=true";

        var serverClient = databaseCommands.ForSystemDatabase() as ServerClient;
        if (serverClient == null)
            throw new ApplicationException("Please use a more intelligent exception here");

        var httpJsonRequest = serverClient.CreateRequest("DELETE", relativeUrl);
        httpJsonRequest.ExecuteRequest();
    }

#3


1  

I want to update your solution, that are the only solution for "deleting" a database.

我想更新您的解决方案,这是“删除”数据库的唯一解决方案。

Actually in the new version (2.0) of RavenDB, which are still unstable, you can delete a database with the new version of the studio.

实际上在RavenDB的新版本(2.0)中仍然不稳定,您可以使用新版本的工作室删除数据库。

You can download it from here: http://hibernatingrhinos.com/builds/ravendb-unstable-v2.0/

你可以从这里下载:http://hibernatingrhinos.com/builds/ravendb-unstable-v2.0/

I'll hope this help you aditionally to the Ayende good answer.

我希望这能帮助你顺利完成Ayende的好回答。

Best, Dario

最好,达里奥