Skip to main content

Get document batch

Gets the next batch of cursor documents

Function GetDocumentBatch(Val Connection, Val Collection, Val CursorID, Val Base = Undefined, Val BatchSize = Undefined, Val Waiting = Undefined) Export

ParameterCLI optionTypeRequiredDescription
Connection-String, ArbitraryConnection or connection string
Collection-StringCollection name
CursorID-NumberCursor ID
Base-StringDatabase name. Current database if not specified
BatchSize-NumberAmount of records in the batch
Waiting-NumberMaximum lock time during awaitData (in ms.)
Returns

Map Of KeyAndValue - Operation result

Caution

NOCLI: this method is not available in CLI version

1C:Enterprise/OneScript code example
Address = "127.0.0.1:1234";
Login = "bayselonarrend";
Password = "12we...";
Base = "main";

ConnectionParams = New Structure("authSource", "admin");
ConnectionString = OPI_MongoDB.GenerateConnectionString(Address, , Login, Password, ConnectionParams);
Connection = OPI_MongoDB.CreateConnection(ConnectionString);

Collection = "new_collection";

Filter = New Structure("stringField", "Text");
Sort = New Structure("doubleField", -1);
Parameters = New Structure("limit,batchSize", 2, 1);

Cursor = OPI_MongoDB.GetCursor(Connection, Collection, Base, Filter, Sort, Parameters);

If Not Cursor["result"] Then
Raise Cursor["error"];
EndIf;

Cursor = Cursor["data"]["cursor"];
DocsArray = Cursor["firstBatch"];
CursorID = Cursor["id"];
ContinueGetting = CursorID > 0;

While ContinueGetting Do

Result = OPI_MongoDB.GetDocumentBatch(Connection, Collection, CursorID, Base); // <---

If Not Result["result"] Then
Raise Result["error"];
EndIf;

ContinueGetting = Result["data"]["cursor"]["id"] > 0;

For Each Record In Result["data"]["cursor"]["nextBatch"] Do
DocsArray.Add(Record);
EndDo;

EndDo;
Result
{
"data": {
"cursor": {
"id": 0,
"nextBatch": [
{
"_id": "6a5d049e81f611be7d1e56ec",
"arrayField": [
"Value1",
"Value2"
],
"boolField": true,
"dateField": "2026-07-19T17:08:46Z",
"docField": {
"number": 10,
"text": "Text"
},
"doubleField": 123.456,
"intField": 200,
"nullField": null,
"stringField": "Text"
}
],
"ns": "main.new_collection"
},
"ok": 1
},
"result": true
}