【问题标题】:Database command 'update' failed: Unknown option to update command: upsert数据库命令“更新”失败:更新命令的未知选项:upsert
【发布时间】:2017-06-23 11:37:59
【问题描述】:

我无法在 mongodb 版本 3.0.12 中执行 upsert 查询,而 ruby​​ gem 版本是 1.x。我正在使用 ruby​​ 版本 1.9.3。我尝试将 mongodb 升级到版本 3.23.4 但仍然面临同样的问题。如果有人知道发生了什么或遇到类似问题,请提供一些见解。

Database command 'update' failed: Unknown option to update command: upsert
/Users/ayushgaur/.rvm/gems/ruby-1.9.3-p551/bundler/gems/mongo-ruby-driver-de949571b660/lib/mongo/db.rb:559:in `rescue in command'
/Users/ayushgaur/.rvm/gems/ruby-1.9.3-p551/bundler/gems/mongo-ruby-driver-de949571b660/lib/mongo/db.rb:555:in `command'
/Users/ayushgaur/.rvm/gems/ruby-1.9.3-p551/bundler/gems/mongo-ruby-driver-de949571b660/lib/mongo/collection_writer.rb:314:in `block in send_write_command'
/Users/ayushgaur/.rvm/gems/ruby-1.9.3-p551/bundler/gems/mongo-ruby-driver-de949571b660/lib/mongo/functional/logging.rb:55:in `block in instrument'
/Users/ayushgaur/.rvm/gems/ruby-1.9.3-p551/bundler/gems/mongo-ruby-driver-de949571b660/lib/mongo/functional/logging.rb:20:in `instrument'
/Users/ayushgaur/.rvm/gems/ruby-1.9.3-p551/bundler/gems/mongo-ruby-driver-de949571b660/lib/mongo/functional/logging.rb:54:in `instrument'
/Users/ayushgaur/.rvm/gems/ruby-1.9.3-p551/bundler/gems/mongo-ruby-driver-de949571b660/lib/mongo/collection_writer.rb:313:in `send_write_command'
/Users/ayushgaur/.rvm/gems/ruby-1.9.3-p551/bundler/gems/mongo-ruby-driver-de949571b660/lib/mongo/collection.rb:1076:in `send_write'
/Users/ayushgaur/.rvm/gems/ruby-1.9.3-p551/bundler/gems/mongo-ruby-driver-de949571b660/lib/mongo/collection.rb:497:in `update'

【问题讨论】:

  • mongo-ruby-driver 不是 2.4 版吗?你为什么使用 1.x 版本?
  • 请提供您使用的实际查询。
  • @eiko 项目中有很多依赖的 gem,所以我不想全部更新。
  • @MaximFedotov 查询类似于:collection.update( { "param" => param, }, { "param1" => param1, "param2" => param2 }, { :upsert =>真的})
  • @eiko 而且它不像 1.x 不支持 upsert 命令。

标签: ruby-on-rails ruby mongodb rubygems


【解决方案1】:

mongo-ruby-driver 1.x 不完全支持 mongodb 3,根据 https://www.mongodb.com/blog/post/announcing-ruby-driver-20-rewrite:

当 mongo gem 版本 2.0 和 mongoid gem 版本 5.0 发布时,有很多理由升级。首先,这些版本支持 MongoDB 3.0 [...] 不会添加新功能,开发工作将仅包括错误修复和支持最新版本服务器所需的最少功能。

我在整个互联网上搜索了有类似问题的人,我发现的唯一人是 pagerbot 的人,他们正在使用 1.x 系列的 gem 和 mongo 3 并得到与您完全相同的错误:

https://github.com/stripe-contrib/pagerbot/issues/46

他们通过更新到 mongo-ruby-driver 2 解决了错误。很抱歉让您与这些依赖项搏斗,但我找不到更简单的答案。

【讨论】:

    猜你喜欢
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 2015-11-26
    • 1970-01-01
    • 2014-08-17
    • 2021-02-17
    • 1970-01-01
    相关资源
    最近更新 更多