2012-02-17 87 views
2

我有Rails和mongodb的一個小問題。我有一個小應用程序,它在開發模式下非常出色。它也適用於生產模式,但是當我進入導軌控制檯時,我看不到任何東西。Rails控制檯和mongodb

[email protected]:/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 
=> [] 

我的配置/初始化/ 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 

,但它也看起來空

$ 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 } 
> 

難道我做錯了什麼?爲什麼我無法看到數據庫中的數據?我如何測試它?

+0

你有沒有搞清楚問題? – 2012-02-22 17:58:15

回答

1

看來你需要運行mmconsole

然後,您將被放入包含MongoMapper且您的數據庫設置爲'mm-test'的irb中。

在你的情況下,可能是你的mongo.rb初始值沒有被尊重,並且你連接到mm-test數據庫而不是「webapp - #{Rails.env}」。

我得到了一些這方面的信息here

7

我認爲這可能與您的查詢語法。我剛碰到同樣的事情,我試圖使用正常的ActiveRecord查詢。我使用MongoDB和Mongoid作爲我的ORM。

,這另一個問題是關係到你的,雖然它也使用Mongoid: mongoid-finders-not-working

我發現成功使用下面的一個「全」查詢:

User.all.to_a