2017-09-13 41 views
0

我收到以下錯誤,當我嘗試連接到遠程數據庫MongoID InvalidMechanism mongodb_cr

"mongodb_cr" is invalid, please use mongodb_cr, mongodb_x509, gssapi or plain. 

我可以沒有問題從我的終端或任何其他應用程序(如robomongo)連接尤斯相同的憑據和身份驗證機制

有什麼疑惑我是"mongodb_cr" is invalid請用mongodb_cr

這是我的mongoid.yml文件的內容

development: 
    clients: 
    default: 
     database: urijijami 
     hosts: 
     - <%= ENV['MONGO_HOST'] || 'localhost' %> 
     options: 
     user: <%= ENV['MONGO_USER'] %> 
     password: <%= ENV['MONGO_PASS'] %> 

     # Change the default authentication mechanism. Valid options are: :scram, 
     # :mongodb_cr, :mongodb_x509, and :plain. Note that all authentication 
     # mechanisms require username and password, with the exception of :mongodb_x509. 
     # Default on mongoDB 3.0 is :scram, default on 2.4 and 2.6 is :plain. 
     auth_mech: mongodb_cr 

    # Configure Mongoid specific options. (optional) 
    options: 
    raise_not_found_error: false 

回答

0

原來沒有MONGO_USER和MONGO_PASS集,所以連接失敗,因爲這一點。我改變了auth_mech選項

<%= 'auth_mech: :mongodb_cr' if ENV['MONGO_USER'].present? %> 

,它現在的作品都完美

0

基於註釋掉區,這是該行應讀什麼:

auth_mech: :mongodb_cr