Skip to main content

Update documents

Updates document data in the collection

Function UpdateDocuments(Val Connection, Val Collection, Val Updates, Val Base = Undefined, Val Parameters = Undefined) Export

ParameterCLI optionTypeRequiredDescription
Connection--dbcString, ArbitraryConnection or connection string
Collection--collStringCollection name
Updates--updatesArray of StructureUpdate array. See GetDocumentUpdateStructure
Base--dbStringDatabase name. Current database if not specified
Parameters--paramsStructure Of KeyAndValueAdditional insert options
Returns

Map Of KeyAndValue - Operation result

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";

// __4 = $
Filter = New Structure("stringField,doubleField", "Text", New Structure("__4gte, __4lte", 100, 150));
Data = New Structure( "__4set", New Structure("doubleField", 999));

Updating = OPI_MongoDB.GetDocumentUpdateStructure(Filter, Data); // Array or single
Result = OPI_MongoDB.UpdateDocuments(Connection, Collection, Updating, Base);
# JSON data can also be passed as a path to a .json file

oint mongodb UpdateDocuments \
--dbc "mongodb://bayselonarrend:12we3456!2154@127.0.0.1:27017/?authSource=admin" \
--coll "new_collection" \
--updates "[{'q':{'category':'electronics'},'u':{'__4set':{'price':'888','discounted':true}},'multi':true,'upsert':false},{'q':{'category':'clothing'},'u':{'__4inc':{'quantity':'5'}},'multi':true,'upsert':false},{'q':{'category':'books'},'u':{'__4push':{'tags':'mass_update'}},'multi':true,'upsert':false},{'q':{'productName':'Special item from array'},'u':{'__4set':{'productName':'Special item from array','category':'special','price':'1111','quantity':'7','inStock':true,'createdDate':'05/26/2026 13:57:46'}},'multi':false,'upsert':true},{'q':{'rating':{'__4lte':'2'}},'u':{'__4set':{'needsImprovement':true},'__4inc':{'quantity':'-2'}},'multi':true,'upsert':false}]" \
--db "main"
Result
{
"result": true,
"data": {
"n": 2,
"nModified": 2,
"ok": 1
}
}