class

Mongo::Bulk

Inherits Reference / Object

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

Instance methods

collection

The target collection.

Source
delete_many(filter, **options)

Delete one or more documents.

Source
delete_one(filter, **options)

Delete a single document.

Source
execute(write_concern : WriteConcern | Nil = nil, bypass_document_validation : Bool | Nil = nil)

Execute the bulk operations stored in this Bulk instance.

Source
insert_one(document)

Insert a single document.

Source
ordered?

Whether the bulk is ordered.

Source
replace_one(filter, replacement, **options)

Replace one document.

Source
update_many(filter, update, **options)

Update many documents.

Source
update_one(filter, update, **options)

Update one document.

Source

Nested types