新手问题 关于 console 查询 mongo 的问题

dxxeng · 2014年07月17日 · 1863 次阅读

这几天在折腾 mongo。按照gorails 的教程设置好了基本配置。然后 generate 了一个简单的 scaffold。但是我发现一个问题。以前用 SQL 的时候,非常喜欢用 rails console,因为直接用数据库客户端连接上去用 SQL 语言查询非常麻烦。不及 ORM 好用。所以换到了 mongo,还是习惯用 rc 进入控制台,想看看数据库的情况。

但是总是碰到这个错误:

Mongoid::Errors::NoSessionConfig:
Problem:
  No configuration could be found for a session named 'default'.
Summary:
  When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect.
Resolution:
  Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash.

, 我的 mongo.yml 文件是默认生成的一点没改:

development:
  sessions:
    default:
      database: myapp_development
      hosts:
        - localhost:27017
      options:
  options:

test:
  sessions:
    default:
      database: myapp_test
      hosts:
        - localhost:27017
      options:
        read: primary
        max_retries: 1
        retry_interval: 0

google 一下找到了一个解决办法,就是使用rails c production,进入以后,错误确实是不见了,也可以使用正常的查询。但是我想知道为什么要这样做?以及是否有别的解决办法?(其实主要是好奇^_^,mongo 的 shell 也很好用,对开发倒是没影响的)

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号