Rails控制台和mongodb

Mar*_*kus 2 ruby-on-rails mongodb mongomapper ruby-on-rails-3

我和Rails和mongodb有一个小问题.我有一个小应用程序,在开发模式下工作得很好.它也可以在生产模式下工作,但是当我进入rails控制台时,我看不到任何内容.

user-001@marcus:/var/www/webapp% rails c RAILS_ENV="production"
You did not specify how you would like Rails to report deprecation notices for your       RAILS_ENV=production environment, please set config.active_support.deprecation to :log,    :notify or :stderr at config/environments/RAILS_ENV=production.rb
Loading RAILS_ENV=production environment (Rails 3.2.1)
1.9.3p0 :001 > User.all
=> [] 
Run Code Online (Sandbox Code Playgroud)

我的config/initialize/mongo.rb看起来像这样

MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
MongoMapper.database = "webapp-#{Rails.env}"

if defined?(PhusionPassenger)
     PhusionPassenger.on_event(:starting_worker_process) do |forked|
     MongoMapper.connection.connect if forked
end
end
Run Code Online (Sandbox Code Playgroud)

但它看起来也是空的

 $ mongo localhost:27017/mail1up-production
 MongoDB shell version: 1.8.2
 Fri Feb 17 18:26:00 *** warning: spider monkey build without utf8 support.  consider        rebuilding with utf8 support
 connecting to: localhost:27017/webapp-production
 > db.mycollection.stats()
 { "errmsg" : "ns not found", "ok" : 0 }
 > 
Run Code Online (Sandbox Code Playgroud)

难道我做错了什么?为什么我看不到数据库中的数据?我该怎么测试呢?

Joe*_*Joe 7

我认为它可能与您的查询语法有关.我刚刚尝试使用正常的ActiveRecord查询.我正在使用MongoDB和Mongoid作为我的ORM.

这个问题与你的有关,虽然它也使用Mongoid: mongoid-finders-not-working

我发现成功使用以下"全部"查询:

User.all.to_a