0
我試圖從腳本初始化一個MongoClient,但我失敗了。 我只是做的是:Ruby MongoClient:從irb初始化成功,從腳本初始化失敗
require 'mongo'
include Mongo
client = MongoClient.new("localhost", 27017)
和失敗,出現以下錯誤:
/var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/cursor.rb:43:in `initialize': undefined method `connection' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/db.rb:564:in `new'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/db.rb:564:in `command'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:591:in `block in check_is_master'
from /usr/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:590:in `check_is_master'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:474:in `connect'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:698:in `setup'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:155:in `initialize'
from ./test.rb:52:in `new'
from ./test.rb:52:in `<main>'
但是,當我嘗試從IRB完全一樣的東西,它的工作原理。
的Ruby版本是:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
IRB是:
/usr/bin/irb1.9.1 --version irb 0.9.6(09/06/30)
我也試圖要求 'RubyGems的',但據我所知,Ruby 1.9中並不需要它。 我忘了什麼嗎?
這對我所描述的工作很好;你能提供一個最小的完整失敗的例子嗎? –
克里斯,這是一個最小的完整失敗的例子。這就是文件中的所有內容......但它在irb中工作... –
它絕對在這裏工作;錯誤被拋出,因爲沒有活動的連接對象,但它應該在此之前被彈出。考慮打開Mongo Ruby驅動程序的錯誤報告。 –