2011-11-30 83 views
0

工作我有一個問題有一個非常簡單的Gemfile:捆綁不mongo_ext

source :rubygems 
gem 'mongo' 
gem 'mongo_ext' 

我安裝了寶石「包安裝」,但它不會加載mongo_ext。

irb(main):001:0> require 'rubygems' 
=> false 
irb(main):002:0> require 'mongo' 

**Notice: C extension not loaded. This is required for optimum MongoDB 
    Ruby driver performance. You can install the extension as follows: 
    gem install bson_ext 

    If you continue to receive this message after installing, make sure that the 
    bson_ext gem is in your load path and that the bson_ext and mongo gems are of 
    the same version. 

=> true 

但是,如果使用系統IRB我是負載:

$ irb 
irb(main):001:0> require 'rubygems' 
=> true 
irb(main):002:0> require 'mongo' 
=> true 
irb(main):003:0> 

也許這種行爲是因爲mongo_ext包括C擴展。

+1

您是否試過'gem install bson_ext',因爲它建議? –

+0

我已安裝它。當我使用'irb'時,它在我需要'mongo'時加載,但是當我使用'mongo exec ruil'時,它不會被加載。 –

回答

2

您需要BSON和bson_ext添加到您的Gemfile:

source :rubygems 
gem 'mongo' 
gem 'mongo_ext' 
gem 'bson' 
gem 'bson_ext' 

而一般來說,它是指定要使用的寶石的版本是個好主意。這樣,即使寶石發生重大更改(或添加了影響您的新bug),您也可以確保代碼正常工作。指定在開始項目時最新的版本,但請小心升級它們。例如:

source :rubygems 
gem 'mongo', '1.5.1' 
gem 'mongo_ext', '0.19.3' 
gem 'bson', '1.5.1' 
gem 'bson_ext', '1.5.1'