【发布时间】:2025-12-05 21:40:03
【问题描述】:
我正在尝试打开我的 MongoDB 模型,但是,我收到以下错误:
MONGODB | xxx.xx.x.xxx:27017 | db.find | FAILED | wrong number of arguments (given 2, expected 1) | 0.013306s
我的 Mongo 凭据是正确的,我可以连接到 Rails 之外的数据库集合。
错误的前几行是:
Started GET "/admin/xsl_sheet" for xxx.xxx.xxx.xxx at 2020-03-03 13:49:54 UTC
Processing by RailsAdmin::MainController#index as HTML
Parameters: {"model_name"=>"xsl_sheet"}
(5.0ms) SELECT `companies`.`name` FROM `companies` WHERE `companies`.`id` = 4
CACHE (0.1ms) SELECT `companies`.`name` FROM `companies` WHERE `companies`.`id` = 4 [["id", "4"]]
CACHE (0.2ms) SELECT `companies`.`name` FROM `companies` WHERE `companies`.`id` = 4 [["id", "4"]]
MONGODB | xxx.xx.x.xxx:27017 | db.saslStart | STARTED | {}
MONGODB | xxx.xx.x.xxx:27017 | db.saslStart | SUCCEEDED | 0.007s
MONGODB | xxx.xx.x.xxx:27017 | db.saslContinue | STARTED | {}
MONGODB | xxx.xx.x.xxx:27017 | db.saslContinue | SUCCEEDED | 0.006s
MONGODB | xxx.xx.x.xxx:27017 | db.saslContinue | STARTED | {}
MONGODB | xxx.xx.x.xxx:27017 | db.saslContinue | SUCCEEDED | 0.006s
MONGODB | xxx.xx.x.xxx:27017 | db.find | STARTED | {"find"=>"TestCompanyNumber2_xsl_sheets", "filter"=>{"assetable_id"=>4}, "limit"=>1, "skip"=>0, "sort"=>{"_id"=>-1}, "projection"=>{"_id"=>1}}
MONGODB | xxx.xx.x.xxx:27017 | db.find | FAILED | wrong number of arguments (given 2, expected 1) | 0.013306s
Rendered /Project/app/views/rails_admin/main/index.html.haml within
layouts/rails_admin/application (349.7ms)
Rendered public/500.html (64.4ms)
wrong number of arguments (given 2, expected 1)
/GEMS/gems/bson-4.8.0-java/lib/bson/hash.rb:115:in `from_bson'
编辑:
这是 rails_admin.rb 中的代码(我相信)它负责从 MongoDB 中提取对象:
c.model XslSheet do
label Proc.new {"Xsl Sheet"}
navigation_label Proc.new {I18n.t('navigation.actions')}
weight 303
navigation_icon 'fa fa-file-excel-o'
list do
scopes [:applicationId]
field :data_file_name
field :updated_at
end
end
【问题讨论】:
-
你能分享一下控制器中的实际代码,它正在执行
find吗? -
@pcrglennon 我已经添加了从 Rails admin 中提取 Mongo 信息的内容
-
哦,我的错,一开始并没有意识到这是通过 rails-admin 的(尽管现在我查看了堆栈跟踪,我应该知道的!)。很抱歉,但我也很困惑,不熟悉 rails-admin 的工作方式。我在问题中添加了该标签(rails-admin),希望这将有助于了解更多有关此问题的人。
-
该错误消息正在调用this line,它试图反序列化响应。也许来自服务器的响应是错误的?
-
@pcrglennon 好的,谢谢 :)
标签: ruby-on-rails mongodb mongoid rails-admin