我下载了 mongo_mapper gem 并成功安装。现在,我在我的应用程序中使用它,它总是抛出异常“没有文件加载 mongo_mapper”。那应该是什么意思?
require 'mongo_mapper'
include mongo
更新:首先使用 require '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