无法使用 mongoid 3.1.0 连接到 mongodb 3.4

Can't connect to mongodb 3.4 using mongoid 3.1.0

我正在尝试连接到托管在 MLab 上的 mongodb,但身份验证失败。

当我启动 rails 应用程序时出现错误:

Moped::Errors::AuthenticationFailure: The operation: #<Moped::Protocol::Commands::Authenticate
@length=168
@request_id=3
@response_to=0
@op_code=2004
@flags=[]
@full_collection_name="heroku_vjmpxxzn.$cmd"
@skip=0
@limit=-1
@selector={:authenticate=>1, :user=>"heroku_vjmpxxzn", :nonce=>"9a254f9ab71432e4", :key=>"79a149a6651d6e8234e6d45718eff7f0"}
@fields=nil>
failed with error 18: "auth failed"

我已经尝试更新 mongoid 版本,但如果我这样做,我将需要更新很多其他 gem,这会消耗大量时间。

那是我的 mongoid.yml 生产配置。

production:
  sessions:
    default:
      database: <database>
      username: <user>
      password: <pass>
      hosts:
        - ds333748-a0.mlab.com:33748
        - ds333748-a1.mlab.com:33748
      options:
          consistency: :strong
          skip_version_check: true
          safe: true

我正在使用:

Gemfile

source 'https://rubygems.org'

ruby "2.3.8"

gem 'rails', '3.2.22.5'
gem 'rest-client'
gem 'bundler', '1.15.2'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

# Gems used only for assets and not required
# in production environments by default.

gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem "cpf_cnpj"
gem "savon"

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'uglifier', '>= 1.0.3'
gem 'adminlte2-rails'
gem 'jquery-rails'
gem 'will_paginate_mongoid'
gem "mongo_session_store-rails3"
gem 'geocoder', '1.3.3'
gem 'test-unit'
gem 'nokogiri'
gem 'sprockets', '~> 2'
gem  "httparty", '0.13.3'

gem 'mongoid-geospatial'
gem 'credit_card_validations'
gem "chartkick"
gem "time_difference"
gem 'newrelic_rpm'
gem 'dropzonejs-rails'
gem 'mongoid_auto_increment', :git => 'git://github.com/teriyakisan/mongoid_auto_increment.git'
gem 'parse-ruby-client', git: 'https://github.com/adelevie/parse-ruby-client.git', ref: '98596a04dfc30295c1d078c58c31b4cea299e8ca'

gem 'websocket-rails', github: 'moaa/websocket-rails', branch: 'threadsocket-rails'
gem 'websocket-rails-js', github: 'websocket-rails/websocket-rails-js', branch: 'sub_protocols'
gem 'faye-websocket', '0.10.0'

gem 'momentjs-rails'

gem "pagarme"
gem "mongoid", ">= 3.1.0"
gem "paperclip", ' 3.1.1'
gem "mongoid-paperclip", :require => "mongoid_paperclip"
gem 'aws-sdk', '< 3.0'
gem "google-api-client"

gem "cucumber-rails", ">= 1.3.0", :group => :test, :require => false
gem 'apipie-rails'
gem "devise", ">= 2.2.3"
gem "quiet_assets", ">= 1.0.1", :group => :development
gem "figaro", ">= 0.5.3"
gem "better_errors", ">= 0.6.0", :group => :development
gem "binding_of_caller", ">= 0.6.9", :group => :development
gem 'client_side_validations'
gem 'fcm'
gem 'redis'
gem 'rack-cors'
gem 'certified'

group :production do
  gem 'thin'  
end

抱歉,但是 mongoid 3.1 于 2013 年发布,mongodb 3.4 于 3 年后的 2016 年发布......这有点道理,但它不会工作...... 您是否考虑过升级 mongoid?或变老 mongodb?

如果无法更改版本,您可以尝试只升级 mongo 驱动程序 (bundle update mongo),看看会发生什么。