MongoDB.TextToBinary
--------------------

Converts a text to JSON for MongoDB.

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

MBS( "MongoDB.TextToBinary"; Text { ; Encoding } ) 

**MBS**( **"MongoDB.TextToBinary";** /\* Converts a text to JSON for MongoDB. \*/  
**$Text**; /\* The text to save.e.g. "Hello World" \*/   
**$Encoding**) /\* Optional; The text encoding for text parameter.   
Default is UTF-8.e.g. "UTF-8" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Text | The text to save. | "Hello World" |  |
| Encoding | The text encoding for text parameter.    Default is UTF-8. | "UTF-8" | Optional |

### Result

Returns JSON or error.

### Description

Converts a text to JSON for MongoDB.  
Reads the text in encoding, converts to base64 and embeds it in a $binary JSON for use in MongoDB.  
### Examples

Convert text to binary:

 MBS ( "MongoDB.TextToBinary"; "Hello World")  
<small>  
Example result:   
{ "$binary" : { "base64" : "SGVsbG8gV29ybGQ=" , "subType" : "00" } </small>### Release notes

- **Version 16.3**
    - Fixed memory leak in MongoDB.NowUTC, MongoDB.Time, MongoDB.ContainerToBinary and MongoDB.TextToBinary functions.
- **Version 13.2**
    - Added [MongoDB.ContainerToBinary](https://www.mbsplugins.eu/MongoDBContainerToBinary.shtml) and [MongoDB.TextToBinary](https://www.mbsplugins.eu/MongoDBTextToBinary.shtml) functions.

### Blog Entries

- [MBS FileMaker Plugin, version 16.3pr1](https://www.mbsplugins.de/archive/2026-06-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [New in MBS FileMaker Plugin 13.2](https://www.mbsplugins.de/archive/2023-05-17/New_in_MBS_FileMaker_Plugin_13/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 13.2pr1](https://www.mbsplugins.de/archive/2023-04-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function is free to use.

Created 15th March 2023 , last changed 15th March 2023

  
[MongoDB.StartTransaction](MongoDBStartTransaction.md) - [MongoDB.Time](MongoDBTime.md)

[HTML Version](MongoDBTextToBinary.shtml)