Module: Mongoid::Relations::Embedded::Batchable

Defined in:
lib/patches/push_each.rb

Instance Method Summary collapse

Instance Method Details

#batch_insert(docs) ⇒ Object



10
11
12
# File 'lib/patches/push_each.rb', line 10

def batch_insert(docs)
  execute_batch_insert(docs, "$push", true)
end

#execute_batch_insert(docs, operation, use_each = false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/patches/push_each.rb', line 14

def execute_batch_insert(docs, operation, use_each = false)
  self.inserts_valid = true
  inserts = pre_process_batch_insert(docs)
  if insertable?
    collection.find(selector).update(
        positionally(selector, operation => { path => use_each ? { '$each' => inserts } : inserts })
    )
    post_process_batch_insert(docs)
  end
  inserts
end