我在 mLab 上使用 MongoDB 来存储我希望在我的 Ruby 应用程序中显示的棋盘游戏的基本集合。我已经完成了一个使用 Mongoid 在本地实现它的教程,但到目前为止,我无法让它与数据库的 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)