mongodb 和 mongo 之间的冲突(mongo-ruby-driver)

2024-01-02

我需要使用两颗宝石mongoid and mongo在我的 Rails 应用程序中。

有什么想法可以解决这个麻烦的问题吗谢谢~

gem 'mongo', '2.0.2',:git => 'git://github.com/mongodb/mongo-ruby-driver.git'
gem 'mongoid', '4.0.0'
# gem "mongo_mapper"

错误信息

Bundler could not find compatible versions for gem "bson":
  In Gemfile:
    mongo (= 2.0.2) ruby depends on
      bson (~> 3.0) ruby

    mongoid (= 4.0.0) ruby depends on
      moped (~> 2.0.0) ruby depends on
        bson (~> 2.2) ruby

UPDATE

Mongoid 很方便,但有时很糟糕,

因为我得到了错误'Client Error: Remaining data too small for BSON object,

甚至我把它包裹起来begin rescue block,它仍然破坏了我的 Rails 应用程序,并停止了导入数据任务,Mongoid 是什么鬼东西!所以我决定放弃使用Mongoid向集合插入新记录,我尝试使用mongo。但它们在我的 Rails 应用程序中再次发生冲突!

  def bulk_insert_to_collection(collection_name)
    model = collection_name.capitalize.constantize.new
    begin
      model.collection.insert(@data_in_chunk)
      # @bulk.execute
    rescue Exception=>err  
      log_error "[#{err}] File #{@file_path}: line of #{i} #{Time.now}"
    rescue Exception => err
      log_error "[#{err}] File #{@file_path}: line of #{i} #{Time.now}"
    rescue => err
       p ex
      log_error "[#{err}] File #{@file_path}: line of #{i} #{Time.now}"
    end
    # @data_in_chunk = []
  end

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

mongodb 和 mongo 之间的冲突(mongo-ruby-driver) 的相关文章

随机推荐