我刚安装了mongoid。我尝试了他们的示例代码,它引发了一个漂亮的错误,并建议“仔细检查您的mongid.yml...”所以我在mongoid.org,where they say上阅读了他们的介绍:"Mongoid配置可以通过mongoid.yml完成“。但我明白,每个人都理所当然地认为,像我这样的菜鸟会知道mongoid.yml在哪里。当然,我可以只使用find -name mongoid.yml,但这不是很奇怪吗?这是每个新的Mongoid用户都要经历的一种痛苦吗?
编辑:好的,这就是我从Mongoid网站上看到的。
require 'mongoid'
class Human
include Mongoid::Document
field :name, type: String
embeds_many :interests
end
class Interest
include Mongoid::Document
field :content, type: String
embedded_in :human
end
ccfu = Human.where( name: "John Doe" )
ccfu.interests.create( content: "criminal activity" )发布于 2013-05-28 20:36:58
如果你没有使用Ruby on Rails,你可以把mongoid.yml放在你喜欢的任何地方,然后在你的代码中,你可以使用load!方法加载它:
Mongoid.load!('path/to/mongoid.yml', :development)或者:
ENV['MONGOID_ENV'] = 'development'
Mongoid.load!('path/to/mongoid.yml')在Ruby On Rails上,它位于config目录中。
https://stackoverflow.com/questions/16792131
复制相似问题