MongoDB.SetSSLOptions
---------------------

Sets the TLS (SSL) options to use when connecting to TLS enabled MongoDB servers.

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

MBS( "MongoDB.SetSSLOptions"; MongoDBRef; ClientCertificateKeyFile; ClientCertificateKeyPassword; CertificateAuthorityFile { ; CertificateAuthorityDirectory; CertificateRevocationListFile; AllowInvalidCertificates; AllowInvalidHostnames } ) 

**MBS**( **"MongoDB.SetSSLOptions";** /\* Sets the TLS (SSL) options to use when connecting to TLS enabled MongoDB servers. \*/  
**$MongoDBRef**; /\* The reference number for the mongo connection.e.g. $MongoDB \*/   
**$ClientCertificateKeyFile**; /\* The native path to the PEM file with the private key to use. \*/   
**$ClientCertificateKeyPassword**; /\* The password for the PEM file with private key. \*/   
**$CertificateAuthorityFile**; /\* The native file path for a CA file.  
  
e.g. get such a file from CURL website:  
https://curl.se/docs/caextract.html \*/   
**$CertificateAuthorityDirectory**; /\* Optional; The native file path to the CA directory. \*/   
**$CertificateRevocationListFile**; /\* Optional; The native file path to the Certificate revocation list file. \*/   
**$AllowInvalidCertificates**; /\* Optional; Whether to do weaker certificate validation.  
Pass 1 to enable or 0 to disable.  
Default is 0 to disallow.e.g. 0 \*/   
**$AllowInvalidHostnames**) /\* Optional; Whether to allow invalid host names.  
Pass 1 to enable or 0 to disable.  
Default is 0 to disallow.  
  
This allows you to disable hostname validation to allow to continue if the hostname doesn't match the certificate.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| MongoDBRef | The reference number for the mongo connection. | $MongoDB |  |
| ClientCertificateKeyFile | The native path to the PEM file with the private key to use. |  |  |
| ClientCertificateKeyPassword | The password for the PEM file with private key. |  |  |
| CertificateAuthorityFile | The native file path for a CA file.      e.g. get such a file from CURL website:   https://curl.se/docs/caextract.html |  |  |
| CertificateAuthorityDirectory | The native file path to the CA directory. |  | Optional |
| CertificateRevocationListFile | The native file path to the Certificate revocation list file. |  | Optional |
| AllowInvalidCertificates | Whether to do weaker certificate validation.   Pass 1 to enable or 0 to disable.   Default is 0 to disallow. | 0 | Optional |
| AllowInvalidHostnames | Whether to allow invalid host names.   Pass 1 to enable or 0 to disable.   Default is 0 to disallow.      This allows you to disable hostname validation to allow to continue if the hostname doesn't match the certificate. | 0 | Optional |

### Result

Returns OK or error.

### Description

Sets the TLS (SSL) options to use when connecting to TLS enabled MongoDB servers.  
A call to MongoDB.SetSSLOptions overrides all TLS options set through the connection string with which the client was constructed.  
All texts can be empty if needed.  
  
See [Files.DeleteLater](FilesDeleteLater.md) to delete a temporary key file when FileMaker quits.  
### Examples

Connect via certificate:

 Set Variable \[ $Mongo ; Value: MBS ( "[MongoDB.New](MongoDBNew.md)" ) \]   
If \[ MBS ("IsError") \]   
 Show Custom Dialog \[ "Failed to create new MongoDB o…" ; $Mongo \]   
 Exit Script \[ Text Result: \]   
End If  
\#   
\# set URL with authentication via certificate   
Set Variable \[ $r ; Value: MBS ( "[MongoDB.SetURI](MongoDBSetURI.md)"; $Mongo ; "mongodb://localhost/?tls=true" ) \]   
If \[ MBS ("IsError") \]   
 Set Variable \[ $x ; Value: MBS ( "[MongoDB.Release](MongoDBRelease.md)"; $Mongo ) \]   
 Show Custom Dialog \[ "Failed to parse connection str…" ; $r \]   
 Exit Script \[ Text Result: \]   
End If  
\#   
\# specify where to find keys   
Set Variable \[ $r ; Value: MBS ( "MongoDB.SetSSLOptions"; $Mongo ; "/Users/cs/Desktop/key.pem"; "test123"; "/Users/cs/Desktop/cacert.pem" ) \]   
Set Variable \[ $r ; Value: MBS ( "[MongoDB.SetAuthMechanism](MongoDBSetAuthMechanism.md)"; $Mongo ; "MONGODB-X509" ) \]   
\#   
\# now connect   
Set Variable \[ $r ; Value: MBS ( "[MongoDB.Connect](MongoDBConnect.md)"; $Mongo ) \]   
If \[ MBS ("IsError") \]   
 Set Variable \[ $x ; Value: MBS ( "[MongoDB.Release](MongoDBRelease.md)"; $Mongo ) \]   
 Show Custom Dialog \[ "Failed to connect to MongoDB." ; $r \]   
 Exit Script \[ Text Result: \]   
End If  
Allow all certificates without checking:

 Set Variable \[ $r ; Value: MBS ( "MongoDB.SetSSLOptions"; $Mongo ; ""; ""; ""; ""; ""; 1; 1) \]  
### See also

- [Files.Delete](FilesDelete.md)
- [Files.DeleteLater](FilesDeleteLater.md)
- [IsError](IsError.md)
- [MongoDB.Connect](MongoDBConnect.md)
- [MongoDB.GetOptions](MongoDBGetOptions.md)
- [MongoDB.New](MongoDBNew.md)
- [MongoDB.Release](MongoDBRelease.md)
- [MongoDB.SetAuthMechanism](MongoDBSetAuthMechanism.md)
- [MongoDB.SetURI](MongoDBSetURI.md)

### Release notes

- **Version 13.4**
    - Added [MongoDB.SetSSLOptions](https://www.mbsplugins.eu/MongoDBSetSSLOptions.shtml) function.

### Blog Entries

- [News in MBS FileMaker Plugin 13.4](https://www.mbsplugins.de/archive/2023-09-20/News_in_MBS_FileMaker_Plugin_1/monkeybreadsoftware_blog_filemaker)
- [Neues MBS Plugin 13.4 für Claris FileMaker](https://www.mbsplugins.de/archive/2023-09-12/Neues_MBS_Plugin_134_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 13.4 for Claris FileMaker - More than 7100 Functions In One Plugin](https://www.mbsplugins.de/archive/2023-09-12/MBS_Plugin_134_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 13.4pr1](https://www.mbsplugins.de/archive/2023-08-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th July 2023 , last changed 24th June 2024

  
[MongoDB.SetPassword](MongoDBSetPassword.md) - [MongoDB.SetURI](MongoDBSetURI.md)

[HTML Version](MongoDBSetSSLOptions.shtml)