我需要在我的Rails应用中使用两个宝石mongoid
和mongo
。
任何想法解决这个麻烦的问题,谢谢〜
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