MongoDB.ReplaceOne
------------------

This replace one document in the collection that match selector with replacement.

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

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

**MBS**( **"MongoDB.ReplaceOne";** /\* This replace one document in the collection that match selector with replacement. \*/  
**$MongoDBRef**; /\* The reference number for the mongo connection.e.g. $MongoDB \*/   
**$selectorJSON**; /\* A JSON containing the query to match the document for updating. \*/   
**$updateJSON**; /\* A JSON containing the replacement document. \*/   
**$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 the document for updating. |  |  |
| updateJSON | A JSON containing the replacement document. |  |  |
| OptionsJSON | Options as JSON. |  | Optional      Added in version **14.4**. |

### Result

Returns JSON or error.

### Description

This replace one document in the collection that match selector with replacement.  
Returns the reply JSON is populated with the fields matchedCount, modifiedCount, upsertedCount, 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

Replace one record:

 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" ) \]   
\# replace a record with a new JSON   
Set Variable \[ $r ; Value: MBS ( "MongoDB.ReplaceOne"; $Mongo ; "{\\"Hello\\": \\"World\\"}"; "{\\"Hello\\": \\"World\\", \\"OtherField\\": 123}") \]   
Show Custom Dialog \[ "Result" ; $r \]   
Set Variable \[ $r ; Value: MBS ( "[MongoDB.Release](MongoDBRelease.md)"; $Mongo ) \]  
### See also

- [MongoDB.Connect](MongoDBConnect.md)
- [MongoDB.DeleteOne](MongoDBDeleteOne.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)

### Release notes

- **Version 14.4**
    - Added OptionsJSON parameter for [MongoDB.ReplaceOne](https://www.mbsplugins.eu/MongoDBReplaceOne.shtml) function.

### Example Databases

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

### Blog Entries

- [Neues MBS Plugin 14.4 für Claris FileMaker](https://www.mbsplugins.de/archive/2024-09-17/Neues_MBS_Plugin_144_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 14.4 for Claris FileMaker](https://www.mbsplugins.de/archive/2024-09-17/MBS_Plugin_144_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.4pr2](https://www.mbsplugins.de/archive/2024-08-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [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 29th July 2024

  
[MongoDB.Rename](MongoDBRename.md) - [MongoDB.SSLLibrary](MongoDBSSLLibrary.md)

[HTML Version](MongoDBReplaceOne.shtml)