MongoDB.UpdateMany
------------------

Updates many documents in collection that matches selector.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [MongoDB](component_MongoDB.md) | [12.3](newinversion123.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "MongoDB.UpdateMany"; MongoDBRef; selectorJSON; updateJSON { ; OptionsJSON } ) 

**MBS**( **"MongoDB.UpdateMany";** /\* Updates many documents in collection that matches selector. \*/  
**$MongoDBRef**; /\* The reference number for the mongo connection.e.g. $MongoDB \*/   
**$selectorJSON**; /\* A JSON containing the query to match documents for updating. \*/   
**$updateJSON**; /\* A JSON containing the update to perform. If updating with a pipeline, a JSON array. \*/   
**$OptionsJSON**) /\* Optional; Options as JSON. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| MongoDBRef | The reference number for the mongo connection. | $MongoDB |  |
| selectorJSON | A JSON containing the query to match documents for updating. |  |  |
| updateJSON | A JSON containing the update to perform. If updating with a pipeline, a JSON array. |  |  |
| OptionsJSON | Options as JSON. |  | Optional |

### Result

Returns OK or error.

### Description

Updates many documents in collection that matches selector.  
To update at most one document see UpdateOne().  
The result JSON is filled out with fields matchedCount, modifiedCount, and optionally upsertedId if applicable. If there is a server error then reply contains either a "writeErrors" array with one subdocument or a "writeConcernErrors" array.   
  
### Examples

Update many records:

 Set Variable \[ $Mongo ; Value: MBS ( "[MongoDB.New](MongoDBNew.md)" ) \]   
Set Variable \[ $r ; Value: MBS ( "[MongoDB.SetURI](MongoDBSetURI.md)"; $Mongo ; "mongodb://localhost/" ) \]   
Set Variable \[ $r ; Value: MBS ( "[MongoDB.Connect](MongoDBConnect.md)"; $Mongo ) \]   
Set Variable \[ $r ; Value: MBS ( "[MongoDB.OpenDatabase](MongoDBOpenDatabase.md)"; $Mongo ; "local" ) \]   
Set Variable \[ $r ; Value: MBS ( "[MongoDB.OpenCollection](MongoDBOpenCollection.md)"; $Mongo ; "test" ) \]   
\# update a lot of records by setting a new field   
Set Variable \[ $r ; Value: MBS ( "MongoDB.UpdateMany"; $Mongo ; "{\\"Hello\\": \\"World\\"}"; "{\\"$set \\": {\\"OtherField\\": 123}}") \]   
Show Custom Dialog \[ "Result" ; $r \]   
Set Variable \[ $r ; Value: MBS ( "[MongoDB.Release](MongoDBRelease.md)"; $Mongo ) \]  
### See also

- [MongoDB.Connect](MongoDBConnect.md)
- [MongoDB.DeleteMany](MongoDBDeleteMany.md)
- [MongoDB.New](MongoDBNew.md)
- [MongoDB.OpenCollection](MongoDBOpenCollection.md)
- [MongoDB.OpenDatabase](MongoDBOpenDatabase.md)
- [MongoDB.Release](MongoDBRelease.md)
- [MongoDB.SetURI](MongoDBSetURI.md)
- [MongoDB.UpdateOne](MongoDBUpdateOne.md)

### Example Databases

- [MongoDB/MongoDB Blog](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/MongoDB/MongoDB%20Blog.shtml#26ScriptAnchor_)
- [MongoDB/MongoDB Test](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/MongoDB/MongoDB%20Test.shtml#6ScriptAnchor_)

### Blog Entries

- [New MongoDB Example](https://www.mbsplugins.de/archive/2022-07-25/New_MongoDB_Example/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 1/2025, Seite 25](https://filemaker-magazin.de/neuigkeit/4282-Appetithappen-FMM_202501)

This function checks for a license.

Created 22nd May 2022 , last changed 12nd June 2022

  
[MongoDB.TransactionState](MongoDBTransactionState.md) - [MongoDB.UpdateOne](MongoDBUpdateOne.md)

[HTML Version](MongoDBUpdateMany.shtml)