Update documents
Updates document data in the collection
- Parameters
- Advanced call ?
Function UpdateDocuments(Val Connection, Val Collection, Val Updates, Val Base = Undefined, Val Parameters = Undefined) Export
| Parameter | CLI option | Type | Required | Description |
|---|---|---|---|---|
| Connection | --dbc | String, Arbitrary | ✔ | Connection or connection string |
| Collection | --coll | String | ✔ | Collection name |
| Updates | --updates | Array of Structure | ✔ | Update array. See GetDocumentUpdateStructure |
| Base | --db | String | ✖ | Database name. Current database if not specified |
| Parameters | --params | Structure Of KeyAndValue | ✖ | Additional insert options |
Returns
Map Of KeyAndValue - Operation result
| Parameter | Description |
|---|---|
| addin_mode | Manual selection of external component connection mode (for 1C): Isolated, NotIsolated |
| dontwait | Creates a background job and returns its data (for 1C and OneScript only) |
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);
- Bash
- CMD/Bat
# 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"
:: 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
}
}