我在mLab上使用MongoDB来存储我希望在我的Ruby应用程序中显示的基本游戏集合。我已经完成了一个使用Mongoid在本地实现它的教程,但到目前为止我无法使用DB的mLab实例。
我将此添加到我的mongoid.yml文件
development:
clients:
default:
uri: 'mongodb://user:password@ds141232.mlab.com:41232/boardgame_banter'
配置文件中自动生成的其他选项,我留空(默认)。
我想了解终端的这两行:
MONGODB | ds141232-a.mlab.com:41232 | boardgame_banter.find | STARTED | {"find"=>"boardgames", "filter"=>{}}
MONGODB | ds141232-a.mlab.com:41232 | boardgame_banter.find | SUCCEEDED | 0.037816999999999996s
我没有错误,但也没有返回文件,生成的index.html为空白...
任何人都可以解释两条线中的第一条MONGODB | ...对我来说,或者至少确认我的假设是否正确?特别是链的最后一部分,这是告诉我过滤后的结果是空的吗?
MONGODB | <<hostname>> | <<database.find()>> | <<STATUS>> | {"find"=><<collection>>, "filter"=>{<<no results??>>}}
更新在@tfogo提出意见后的建议中
在我的控制器中:
# GET /boardgames
# GET /boardgames.json
def index
@boardgames = Boardgame.all
@log = Boardgame.all.to_a
puts "LOG: #{@log}"
end
在控制台中生成以下空Log语句:
Started GET "/boardgames" for 127.0.0.1 at 2018-03-02 11:25:00 +0100
Processing by BoardgamesController#index as HTML
D, [2018-03-02T11:25:00.186878 #12983] DEBUG -- : MONGODB | ds141232-a.mlab.com:41232 | boardgame_banter.find | STARTED | {"find"=>"boardgames", "filter"=>{}}
D, [2018-03-02T11:25:00.223330 #12983] DEBUG -- : MONGODB | ds141232-a.mlab.com:41232 | boardgame_banter.find | SUCCEEDED | 0.035911000000000005s
LOG: [#<Boardgame _id: 5a984b439de90b3769420f2d, name: nil, rating: nil, minplayer: nil, maxplayer: nil, duration: nil, owner: nil>]
Rendering boardgames/index.html.erb within layouts/application
D, [2018-03-02T11:25:00.235908 #12983] DEBUG -- : MONGODB | ds141232-a.mlab.com:41232 | boardgame_banter.find | STARTED | {"find"=>"boardgames", "filter"=>{}}
D, [2018-03-02T11:25:00.274734 #12983] DEBUG -- : MONGODB | ds141232-a.mlab.com:41232 | boardgame_banter.find | SUCCEEDED | 0.038311s
Rendered boardgames/index.html.erb within layouts/application (42.3ms)
Completed 200 OK in 127ms (Views: 76.9ms)