gpt4 book ai didi

ruby - 使用 GridFS 时出现 "Document exceeds allowed max BSON size. The max is 16777216."错误

转载 作者:可可西里 更新时间:2023-11-01 10:28:35 25 4
gpt4 key购买 nike

我正在尝试使用 GridFS 和 ruby​​ 在我的 mongo 数据库中插入一个 33 MB 的视频文件,并且我有一个系统的“文档超出允许的最大 BSON 大小。最大值为 16777216。”。我认为在 mongo 集合中插入大于 16 MB 的文件的唯一方法是使用 Gridfs,所以我怀疑我做错了,即使我复制/粘贴了 Ruby 驱动程序示例 (http://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial/#gridfs)。

我正在使用 Ruby 2.2.1、mongo 驱动程序 2.0.4 和 mongo db 3.0.1。我的代码:

eDatabase = Mongo::Client.new(......)
@grid = @eDatabase.database.fs


myvideo = File.open("files/33mo.mov", 'rb')

grid_file = Mongo::Grid::File.new(myvideo.read, :filename => "myvideo.mov")
@grid.insert_one(grid_file)

还有我的日志:

21/05/2015 11:12:25] ERROR : Exception in main loop : Document exceeds allowed max BSON size. The max is 16777216.
[21/05/2015 11:12:25] ERROR : Backtrace : /Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/protocol/serializers.rb:157:in `serialize'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/protocol/message.rb:153:in `block in serialize_fields'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/protocol/message.rb:141:in `each'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/protocol/message.rb:141:in `serialize_fields'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/protocol/message.rb:70:in `serialize'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/server/connection.rb:123:in `block in write'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/server/connection.rb:122:in `each'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/server/connection.rb:122:in `write'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/server/connectable.rb:66:in `block in dispatch'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/loggable.rb:44:in `log'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/loggable.rb:65:in `log_debug'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/server/connectable.rb:65:in `dispatch'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/operation/executable.rb:35:in `block in execute'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/server/connection_pool.rb:99:in `with_connection'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/server/context.rb:63:in `with_connection'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/operation/executable.rb:34:in `execute'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/operation/write/insert.rb:71:in `execute_write_command'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/operation/write/insert.rb:61:in `execute'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/collection.rb:196:in `insert_many'
/Users/Atome/.rvm/gems/ruby-2.2.1/gems/mongo-2.0.4/lib/mongo/grid/fs.rb:78:in `insert_one'
server.rb:530:in `handle_addobject_message'

仅供引用,server.rb:530 行对应于

@grid.insert_one(grid_file)

注释:

  • 对于 < 16 MB 的文件,同样的代码也能正常工作,即插入机会文档和文件文档
  • 当我使用 mongofiles 命令时一切正常...
  • 数据库中的其他插入在我的应用程序中工作正常

谢谢你的帮助

最佳答案

根据 mongodb jira ticket RUBY-946 ,这是一个错误,应该在新发布的 Ruby 驱动程序 2.0.5 中得到纠正。请参阅 this google group 中的评论

关于ruby - 使用 GridFS 时出现 "Document exceeds allowed max BSON size. The max is 16777216."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30369561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com