---
schema_version: "1"
id: 2d8b0722b65fb80234beab828a05027905bf4999210bcae7fa9c064768a2525e
title: MongoDB Connector 6.3 Examples
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mongodb-connector/6.3/mongodb-connector-examples.md
canonical_url: https://docs.mulesoft.com/mongodb-connector/6.3/mongodb-connector-examples
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e53e852dfc4cfa81694b2eda48f498cfa2fd3d53eaa28e4ca70eb829537bb753
description: MuleSoft Documentation Site
release: "6.3"
latest: false
---
---
product: MongoDB Connector
version: 6.3
---

# MongoDB Connector 6.3 Examples

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## Invoke an Operation

To invoke a simple operation, such as the **Insert Document** operation, follow these steps:

1.  In Studio, click **HTTP** and drag the **Listener** operation to the canvas.

2.  From the palette, select **MongoDB** and drag the Insert Document operation into your flow by
    placing it to the right of **HTTP Listener**.

3.  Configure the connector by selecting the **Connector Configuration** you created in the previous
    section, choosing the operation to invoke, and setting the **Collection name**.

4.  From the palette, drag the **Transform Message** component to the left of MongoDB Connector.

5.  Click **Transform Message** and enter two key-value pairs:

    ```dataweave
    %dw 2.0
    %output application/json
    ---
    {
    	name:"Peter",
    	age:"42"
    }
    ```

6.  From the Mule Palette view, drag other **Transform Message** components to the right of MongoDB
    Connector.

7.  Click **Transform Message** and set the output to `application/json`:

    ```dataweave
    %dw 2.0
    output application/json
    ---
    payload
    ```

### XML for Invoke an Operation

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
	http://www.mulesoft.org/schema/mule/http
	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
	http://www.mulesoft.org/schema/mule/ee/core
	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
	http://www.mulesoft.org/schema/mule/core
	http://www.mulesoft.org/schema/mule/core/current/mule.xsd
	http://www.mulesoft.org/schema/mule/http
	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
	http://www.mulesoft.org/schema/mule/ee/core
	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
	http://www.mulesoft.org/schema/mule/mongo
	http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd">

	<configuration-properties file="mule-app.properties" />
	<http:listener-config name="HTTP_Listener_config"
		doc:name="HTTP Listener config">
		<http:listener-connection host="0.0.0.0"
			port="8081" />
	</http:listener-config>
	<mongo:config name="MongoDB_Config" doc:name="MongoDB Config">
		<mongo:connection database="${database}">
			<mongo:server-addresses >
				<mongo:server-address host="${host}" port="${port}"/>
			</mongo:server-addresses>
		</mongo:connection>
    </mongo:config>

    <flow name="create-mongo-record-flow" >
        <http:listener
				  config-ref="HTTP_Listener_config" path="/create"
              doc:name="Listener" />
        <ee:transform doc:name="Set Payload and Document Content">
            <ee:message>
                <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
	name:"Pity",
	age:"31"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <mongo:insert-document config-ref="MongoDB_Config"
               doc:name="Insert document"
               collectionName="${collection}" />
        <logger level="INFO" doc:name="Logger"
	  message="New document:  #[payload]" />
    </flow>
</mule>
```

## See Also

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Salesforce Help](https://help.salesforce.com)
