FireDAC.Phys.MongoDBWrapper.TMongoCollection.BeginBulk
Delphi
procedure BeginBulk(AOrdered: Boolean = True);
C++
void __fastcall BeginBulk(bool AOrdered = true);
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
procedure function |
public | FireDAC.Phys.MongoDBWrapper.pas FireDAC.Phys.MongoDBWrapper.hpp |
FireDAC.Phys.MongoDBWrapper | TMongoCollection |
Description
Starts a bulk operation on the collection.
After you call BeginBulk, call Insert, Update, and Remove as many times as you need to define the changes that you want to apply to the collection. During the bulk operation, these calls do not submit any change to the actual database, they simply record the intended change in memory.
Once you have applied all the desired changes in memory, call EndBulk to submit your changes to the database. This finishes the bulk operation, to start a new bulk operation you must call BeginBulk again.
To abort a bulk operation without submitting any change to the database, call CancelBulk.
You can read the value of IsBulk at any time to determine whether you are defining a bulk operation (True
) or not (False
).
Example
The following example removes any restaurant named "La Bella Italia" from the collection, and adds a new restaurant with that name to the collection.
MongDB shell:
var bulk = db.restaurants.initializeOrderedBulkOp();
bulk.find({ name: "La Bella Italia" }).remove()
bulk.insert({
"name": "La Bella Italia",
"cuisine": "Italian",
"grades": [
{
"date": ISODate("2015-11-02T14:38:00Z"),
"grade": "A",
"score": 8
}
]
})
bulk.execute()
Delphi:
MyCollection.BeginBulk;
MyCollection.Remove
.Match
.Add('name', 'La Bella Italia')
.&End
.Exec;
MyDocument := TMongoDocument.Create(MyConnection.Env)
.Add('name', 'La Bella Italia')
.Add('cuisine', 'Italian')
.BeginArray('grades')
.BeginObject('')
.Add('date', ISO8601ToDate('2015-11-02T14:38:00Z'))
.Add('grade', 'A')
.Add('score', 8)
.EndObject
.EndArray;
MyCollection.Insert(MyDocument);
MyDocument.Free;
MyCollection.EndBulk;
C++:
MyCollection->BeginBulk();
MyCollection->Remove()
->Match()
->Add("name", String("La Bella Italia"))
->End()
->Exec();
TMongoDocument* MyDocument = new TMongoDocument(MyConnection->Env);
MyDocument
->Add("name", String("La Bella Italia"))
->Add("cuisine", String("Italian"))
->BeginArray("grades")
->BeginObject("")
->Add("date", ISO8601ToDate("2015-11-02T14:38:00Z"))
->Add("grade", String("A"))
->Add("score", 8)
->EndObject()
->EndArray();
MyCollection->Insert(MyDocument);
delete MyDocument;
MyCollection->EndBulk();