Class: Embulk::Output::Mongodb

Inherits:
OutputPlugin
  • Object
show all
Defined in:
lib/embulk/output/mongodb.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.transaction(config, schema, count, &control) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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

Instance Method Details

#abortObject



51
52
# File 'lib/embulk/output/mongodb.rb', line 51

def abort
end

#add(page) ⇒ Object



40
41
42
43
44
45
46
# 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

#closeObject



37
38
# File 'lib/embulk/output/mongodb.rb', line 37

def close
end

#commitObject



54
55
56
57
# File 'lib/embulk/output/mongodb.rb', line 54

def commit
  task_report = {}
  return task_report
end

#finishObject



48
49
# File 'lib/embulk/output/mongodb.rb', line 48

def finish
end

#initObject

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

task_reports = yield(task)

next_config_diff = {}
return next_config_diff

end



31
32
33
34
35
# File 'lib/embulk/output/mongodb.rb', line 31

def init
  # initialization code:
  @client = Mongo::Client.new(task['uri'])
  @collection = @client[task['collection']]
end