2016-10-28 26 views
1

當您啓動rethinkdb實例時,它將自動創建一個名爲'test'的數據庫。當你運行多個實例和集羣他們使用rethinkdb proxy這導致問題:如何防止RethinkDB創建測試數據庫

Database name conflict: test is the name of more than one database

如果試圖刪除數據庫即使用

r.dbDrop('test').run(conn, function(result) { 
    console.log(result) // Will result in error 
}); 

這將產生以下錯誤:

ReqlOpFailedError: Database 'test' is ambiguous; there are multiple databases with that name in r.dbDrop("test")

那麼如何防止RethinkDB創建'tes t'數據庫自動?或者如果你遇到名稱衝突如何刪除數據庫?

回答

1

如果使用rethinkdb create創建一個數據目錄,沒有test將要創建數據庫。

例如,如果rethinkdb_data不存在,這將不test數據庫中創建它:

rethinkdb create 
rethinkdb 

這將做同樣的,但使用-d指定數據目錄的位置:

rethinkdb create -d /var/lib/rethinkdb/data 
rethinkdb -d /var/lib/rethinkdb/data 
0

經過一段時間的挖掘,我沒有找到任何好的選項來防止RethinkDB在啓動時嘗試創建默認的test數據庫。上述問題僅在羣集節點使用不同的數據目錄時纔會發生。否則,他們不會嘗試創建額外的test數據庫,因爲其他節點只會識別它已存在(由第一個啓動的節點創建)。

我最終通過在rethinkdb數據庫的db_config表中列舉了啓動期間名爲test的所有數據庫來解決此問題。

例子:

// Read from the database 'rethinkdb' that holds information about other databases 
r.db("rethinkdb") 

// Table db_config contains database id, name information 
.table("db_config") 

// Filter by name 'test' 
.filter({name: "test"}) 
.run(conn, function(err, cursor) { 

    // Get results from cursor by id and rename 
    cursor.each(function(err, result){ 
     r.db("rethinkdb") 
      .get(result.id) 
      .update({name: "other_name"}) 
      .run(conn, function(err, result) { 
       console.log(result.replaced); 
      }); 
    }); 
}); 
相關問題