Rubyを使用したMongomapperを使用する例外:「Mongo_Mapperをロードするファイルなし」
-
27-09-2019 - |
質問
Mongo_Mapper GEMをダウンロードし、正常にインストールしました。今、私はアプリでそれを使用しており、それは常に例外「Mongo_Mapperをロードするためのファイルなし」をスローします。それはどういう意味ですか?
require 'mongo_mapper'
include mongo
更新:「Rubygems」を最初に使用した後。私の元の問題はなくなった今、別の奇妙な問題があります:
次のことがわかります。
**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.
すでにbson_extをインストールしていますが、この例外を投げ続けています!
更新2:BSON警告はなくなりましたが、顧客コレクションのアイテムをリストすることはできません。
require 'rubygems'
require 'mongo_mapper'
include Mongo
MongoMapper.database = 'Northwind'
class Customer
include MongoMapper::Document
key :FirstName, String
key :LastName, String
key :UserName, String
end
customers = Customer.all
puts customers.count # this always is 0. It should be 1 since there is one item in the Customers collection
puts customers
解決
宝石を含める前に、Rubygemsを含める必要があります。
require 'rubygems'
require 'mongo_mapper'
私はあなたの次のラインもかなり確信しています include mongo
間違っています、おそらくあなたが望むでしょう include Mongo
. 。あなたの計画は使用することであるので、実際にあなたはおそらく何も望んでいません MongoMapper
, 、ドライバーではありません。
アップデート:
As for the bson_ext
事、それは例外ではなく、単なる警告です。明らかに、生産の使用については、これを整理したいと思うでしょう。最新の宝石をインストールすることを確認することで、これを行うことができます。 sudo gem install mongo bson_ext mongo_mapper
これは(2010年10月4日現在)、Mongo 1.1、BSON_EXT 1.1、およびMongo_Mapper 0.8.4をインストールしたことを伝えます。
更新2:
もっと情報が必要です。あなたが期待する顧客はMongo Shellに現れますか?どのように挿入しましたか?コレクションの名前は正しいですか?
したがって、データセットを作成するために.NETのものを使用し、今すぐ変更できない場合は、Mongomapperドキュメントにコレクション名を手で指定できます。そのようです:
class Customer
include MongoMapper::Document
set_collection_name 'Customers'
# other stuff
end