Mongoid YAML Configuration

时间:2015-07-31 20:26:20

标签: mongodb mongoid yaml

In my YML file for Mongo, it fails on the below:

development:
  sessions:
    default:
      database: library
      username: lib_user
      password: <%= ENV['MONGO_PASSWORD'] %>
      hosts:
        - <%= ENV['MONGO_HOST'] %>:<%= ENV['MONGO_PORT'] %>

The last line in particular is where the error occurs. The error is below.

Psych::SyntaxError: (<unknown>): did not find expected key while parsing a block mapping at line 26 column 11

If I remove the environment variable for the port, everything works fine. What syntax issue am I missing here?

1 个答案:

答案 0 :(得分:0)

该文件中的YAML没有任何问题,尽管我希望在最后一行冒号后面有一个空格(以便hosts的值是一个键值对的列表,而不是字符串列表。)

但是,Psych会抱怨它试图对从YAML读入的标量进行扩展,如果在环境中没有定义<%= ENV['MONGO_HOST'] %>MONGO_HOST会抛出该错误。如果您尝试设置该值,则应加载YAML文件(如果未定义MONGO_PORT,则可能会抱怨第26行第36行。)