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

时间:2015-04-25 00:36:59

标签: ruby-on-rails mongodb mongoid

我需要在我的Rails应用中使用两个宝石mongoidmongo

任何想法解决这个麻烦的问题,谢谢〜

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

更新

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

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

甚至我把它包装在begin rescue block中,它仍然会破坏我的Rails应用程序,并停止导入数据任务,这是什么吮吸Mongoid!所以我决定放弃使用Mongoid将新记录插入到集合中,我尝试使用mongo。但是我们的Rails应用程序中又出现了冲突,WTH再次出现!

  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

0 个答案:

没有答案