# How to Forward Logs from a MongoDB Cluster MongoDB is a source-available cross-platform document-oriented database program for high-volume storage. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. Log forwarding allows you to transmit log data from any number of sources to a centralized database cluster. You can do so by creating and managing log sinks for your database clusters via the [control panel](#forward-logs-using-the-control-panel) or the [API](#create-a-log-sink-using-the-api). MongoDB supports forwarding to OpenSearch and Elasticsearch. You can 1-Click deploy these tools to a Droplet from [the Databases section of the DigitalOcean Marketplace](https://marketplace.digitalocean.com/category/databases). When forwarding logs to or from Managed Databases, all default configuration options, such as the default logging message level, are determined by the forwarding database engine. You can only forward logs from Managed MongoDB to Managed OpenSearch if you add the MongoDB cluster’s node IPs to the OpenSearch cluster’s trusted sources. ## Create a Log Sink Using the API To create a database using the API, you need to provide values for the `sink_name`, `sink_type`, and `config` fields, which specify the name of the log sink, its type (`elasticsearch` or `opensearch`), and your desired URL or server/port configuration, respectively. ## How to create a log sink using the DigitalOcean API To set up log forwarding: 1. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) with the appropriate scope, and save it for use with the API. 2. Send a POST request to `/v2/databases/$DATABASE_ID/logsink`. ### Payload ```shell { "config": { "server": "192.168.0.1", "port": 514, "tls": false, "format": "rfc5424" } } ``` ### cURL ```shell curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ -d '{"sink_name": "logsink", "sink_type": "elasticsearch", "config": {"server": "192.168.10.1", "port": 514, "tls": false, "format": "rfc5424"}}' \ "https://api.digitalocean.com/v2/databases/9cc10173-e9ea-4176-9dbc-a4cee4c4ff30/logsink" ``` ## Forward Logs Using the Control Panel To forward logs from a database cluster in the control panel, go to the [**Databases** page](https://cloud.digitalocean.com/databases), then select your database cluster. Click the name of the cluster to go to its **Overview** page, then click the **Settings** tab. ![Cluster settings page.](https://docs.digitalocean.com/screenshots/databases/mongodb-settings.f2e50a2e41b3bf6613b34bb43b4a7a00e24a4a177b4c9e3273265124ce8ac195.png) On the **Settings** page, in the **Log forwarding** section, click **Edit**. Select the service you want to forward logs to. ![Log forwarding service selection screen.](https://docs.digitalocean.com/screenshots/databases/mongodb-log-forwarding-services.065e99865b9c4c81a3de28b5f3c787c46d7c6f6719c19ba86b15fd3e65267d6f.png) Enter your destination name, endpoint URL, and index prefix. You can also click **Show advanced configuration options** to edit the log sink’s maximum days to store logs, request timeout (in seconds), and CA certificate for authentication. To confirm your changes, click **Add destination**. ![Forward logs to OpenSearch popup.](https://docs.digitalocean.com/screenshots/databases/forward-logs-to-opensearch.d46b2b9299c4f0c7a12a7398b3ece165caa4fab083414fb2874f9e0d8fc8a081.png)