class Embulk::Output::Mongodb

Public Class Methods

transaction(config, schema, count) { |task| ... } click to toggle source
# File lib/embulk/output/mongodb.rb, line 8
def self.transaction(config, schema, count, &control)
  # configuration code:
  task = {
    'uri' => config.param('uri', :string, default: 'mongodb://127.0.0.1:27017/test'), # string, optional
    'collection' => config.param('collection', :string)           # string, required
  }

  # resumable output:
  # resume(task, schema, count, &control)

  # non-resumable output:
  task_reports = yield(task)
  next_config_diff = {}
  return next_config_diff
end

Public Instance Methods

abort() click to toggle source
# File lib/embulk/output/mongodb.rb, line 51
def abort
end
add(page) click to toggle source
# File lib/embulk/output/mongodb.rb, line 40
def add(page)
  # output code:
  page.each do |record|
    hash = Hash[schema.names.zip(record)]
    @collection.insert_one(hash)
  end
end
close() click to toggle source
# File lib/embulk/output/mongodb.rb, line 37
def close
end
commit() click to toggle source
# File lib/embulk/output/mongodb.rb, line 54
def commit
  task_report = {}
  return task_report
end
finish() click to toggle source
# File lib/embulk/output/mongodb.rb, line 48
def finish
end
init() click to toggle source

def self.resume(task, schema, count, &control)

task_reports = yield(task)

next_config_diff = {}
return next_config_diff

end

# File lib/embulk/output/mongodb.rb, line 31
def init
  # initialization code:
  @client = Mongo::Client.new(task['uri'])
  @collection = @client[task['collection']]
end