class Mongo::Bulk

Overview

A bulk operations builder.

# A Bulk instance can be obtained by calling `.bulk()` on a collection.
bulk = collection.bulk(ordered: true)
# Then, operations can be added…
500.times { |idx|
  bulk.insert_one({number: idx})
  bulk.delete_many({number: {"$lt": 450}})
}
# …and they will be performed once the bulk gets executed.
bulk_result = bulk.execute(write_concern: Mongo::WriteConcern.new(w: 1))
pp bulk_result

Defined in:

cryomongo/bulk.cr

Instance Method Summary

Instance Method Detail

def collection : Mongo::Collection #

The target collection.


def delete_many(filter, **options) #

Delete one or more documents.


def delete_one(filter, **options) #

Delete a single document.


def execute(write_concern : WriteConcern? = nil, bypass_document_validation : Bool? = nil) #

Execute the bulk operations stored in this Bulk instance.


def insert_one(document) #

Insert a single document.


def ordered? : Bool #

Whether the bulk is ordered.


def replace_one(filter, replacement, **options) #

Replace one document.


def update_many(filter, update, **options) #

Update many documents.


def update_one(filter, update, **options) #

Update one document.