gpt4 book ai didi

ruby-on-rails - Rails 控制台和 mongodb

转载 作者:可可西里 更新时间:2023-11-01 09:57:09 25 4
gpt4 key购买 nike

我有一个关于 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
=> []

我的 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

但它看起来也是空的

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

我做错了什么吗?为什么我看不到数据库中的数据?我该如何测试它?

最佳答案

我认为这可能与您的查询语法有关。我刚刚遇到了同样的事情,我试图使用普通的 ActiveRecord 查询。我使用 MongoDB 和 Mongoid 作为我的 ORM。

另一个问题与您的问题有关,尽管它也使用了 Mongoid: mongoid-finders-not-working

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

User.all.to_a

关于ruby-on-rails - Rails 控制台和 mongodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9332793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com