我正在尝试在我的Rails应用程序中升级Mongoid。
我的Gemfile现在包含:
mongoid 5.0.2 (was 4.0.0)
bson 4.0.0 (was 2.3.0)
moped 1.5.3 (was 2.0.2)
mongo 2.2.1
rails 4.2.3
根据the Docs我已更新mongoid.yml
以反映所需的更改:
development:
clients:
default:
database: my_db_name
hosts:
- localhost:27017
options:
options:
我的application.rb
看起来像这样:
require File.expand_path('../boot', __FILE__)
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
Bundler.require(:default, Rails.env)
module MyApp
class Application < Rails::Application
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
config.generators do |g|
g.orm :mongoid
end
end
end
但是现在,每当我尝试连接数据库时,我都会得到这个堆栈跟踪:
ArgumentError: comparison of Fixnum with nil failed
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/protocol/message.rb:117:in `>'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/protocol/message.rb:117:in `deserialize'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/server/connectable.rb:107:in `block in read'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/server/connectable.rb:91:in `ensure_connected'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/server/connectable.rb:106:in `read'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/server/connection.rb:180:in `deliver'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/server/connection.rb:125:in `block in dispatch'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/monitoring/publishable.rb:47:in `publish_command'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/server/connection.rb:124:in `dispatch'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/operation/executable.rb:36:in `block in execute'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/server/connection_pool.rb:108:in `with_connection'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/server/context.rb:63:in `with_connection'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/operation/executable.rb:34:in `execute'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/database.rb:158:in `command'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/collection/view/readable.rb:136:in `block in count'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/retryable.rb:51:in `call'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/retryable.rb:51:in `read_with_retry'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongo-2.2.1/lib/mongo/collection/view/readable.rb:135:in `count'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongoid-5.0.2/lib/mongoid/contextual/mongo.rb:59:in `block in count'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongoid-5.0.2/lib/mongoid/contextual/mongo.rb:488:in `try_cache'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongoid-5.0.2/lib/mongoid/contextual/mongo.rb:59:in `count'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongoid-5.0.2/lib/mongoid/contextual/mongo.rb:86:in `destroy'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/mongoid-5.0.2/lib/mongoid/contextual.rb:20:in `destroy'
from (irb):1
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in `start'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/me/.rvm/gems/ruby-2.1.2@my-app/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'2.1.2
此外,当我查看服务器日志时,每隔30秒左右添加一行新文本:
MONGODB | wrong number of arguments (1 for 0)
知道为什么会这样吗?
答案 0 :(得分:0)
看起来你的ruby版本早于2.2.1并且从mongo-ruby-driver回溯判断它可能需要ruby 2.2.1 +。