# MongoDB Destination

MongoDB is a document-oriented database in which one collection holds different documents. The *MongoDB Destination* object in Astera Data Stack, provides functionality to write data onto it. This component provides functionality to control how data should be written in collections.

While writing data, the number of fields, content, and size of the document can differ from one document to another. This can be easily catered to by including configurations on write concerns that describe level of acknowledgment from MongoDB for write operations.

MongoDB is mainly used for Big Data.

### Using the MongoDB Destination object in Astera

The *MongoDB Destination* object can be used to map incoming data from a source to the MongoDB server. MongoDB makes it easier for users to store structured and unstructured data both.

For our use case, we already have an *XML/JSON Source* object configured in a Dataflow.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FwoVs9bVQeA42JoYvEdmK%2Fimage.png?alt=media&#x26;token=29326af8-fa01-4d6b-ae75-40145a446f54" alt=""><figcaption></figcaption></figure>

1. To start, drag-and-drop the *MongoDB Destination* object from the *Destinations* section of the Toolbox onto the Dataflow.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FfSB8ltoO2fLJ86yaxNce%2Fimage.png?alt=media&#x26;token=3f29ac23-1259-4680-86aa-e4ce14e475bd" alt=""><figcaption></figcaption></figure>

2. Right-click on the *MongoDB Destination* object and select *Properties* from the context menu.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Flm4grAf6Yo4Hf2Gk0Bgr%2Fimage.png?alt=media&#x26;token=65bd07d9-793a-400f-9015-5e2a198ed57f" alt=""><figcaption></figcaption></figure>

This will open a new window.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F7rkxLpyDFSeXHNRSBpNI%2Fimage.png?alt=media&#x26;token=2fd0d98e-bd07-437d-bb38-390f242b6bf5" alt=""><figcaption></figcaption></figure>

*User Name:* This is where we enter the user name of the MongoDB or Local Server

*Password:* The password of the MongoDB or Local Server is used here

*Primary Server Name:* The name of the primary cluster is used here

*Database:* This is where we select the database on which we wish to write the data.

*Authentication Database:* This is the database used for authentication.

*Port:* The port is used to handle incoming and outgoing requests to the server

*Enable Set of Replica:* Selecting this checkbox allows the use of a secondary cluster

*Secondary Server Name:* This name of the secondary cluster is used here

*Use TLS:* Select this option if the server requires TLS security.

3. Once your credentials have been filled, test the connection, and click *Next.*

For our use case, we have input the credentials to use the *MongoDB Destination* for our local server.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FpA21G71DclRl1zcHK68g%2Fimage.png?alt=media&#x26;token=3507c200-7db3-42ce-9444-8be56bf4c9d8" alt=""><figcaption></figcaption></figure>

We will now be taken to the *MongoDB Pick Collection* screen.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fx4ZS4qFspaaBT9dGq0HA%2Fimage.png?alt=media&#x26;token=c4045ff0-2fed-4274-a35d-ba582d577eab" alt=""><figcaption></figcaption></figure>

4. For our use case, we will select *Create/Replace* and add a new Collection.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FqxHXCUnXr1EYafiLAXUM%2Fimage.png?alt=media&#x26;token=a4ee633d-3907-411e-a283-0020fc6061a9" alt=""><figcaption></figcaption></figure>

*Database Operations –* These operations are used when we are picking an already existing collection.

*Insert:* To insert a new record into the collection.

*Update:* To update an existing record in the collection.

*Delete:* To delete a record from the collection.

*Upsert:* To insert and update a record in the collection.

*Select Fields for matching database records:* Selecting from this drop-down menu lets the user select fields based on which to match the records for the selected database operation.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FCINudkQwlsLymZVBcvwq%2Fimage.png?alt=media&#x26;token=d3daeaa4-a124-4c90-8c34-8b50eb79e048" alt=""><figcaption></figcaption></figure>

*Write Concern Options –* Selecting from these options lets the server provide an acknowledgment to the user based on how the process was carried out.

*ACKNOWLEDGED:* This will return an acknowledgment in the Job trace window if the process stops after getting an error or if the process successfully completes.

*UNACKNOWLEDGED:* This option will not return an acknowledgment, no matter how the data write is carried out.

*MAJORITY:* If there are multiple primary and secondary servers, this option will return when the majority of the servers have been processed.

*W1:* Selecting this option will return an acknowledgment when the primary server has been processed.

*W2:* Selecting this option will return an acknowledgment when the primary server and one secondary server have been processed.

*W3:* Selecting this option will return an acknowledgment when the primary server and two secondary servers have been processed.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F7eVXRqLLOwCJ4ZVtoRcu%2Fimage.png?alt=media&#x26;token=25ef293c-b74e-4c3c-9801-d42e366448fc" alt=""><figcaption></figcaption></figure>

*Data Load Options –* These options let the user define how the data is going to be loaded into the database.

*Bulk insert with batch size:* This will insert all records divided into batch sizes that the user has defined.

*Bulk insert with all records in one batch:* This will insert all records in a single batch.

*Use single record insert:* This option will treat every record individually and insert them one by one.

*Select Type of Bulk Insert:* Selecting from this drop-down menu lets the user define whether the Bulk Insert will be *Ordered* or *UnOrdered.*

In the case of *Ordered*, data writing will be stopped if an error is encountered between record insertions.

In the case of *UnOrdered,* data writing will continue despite any errors being encountered.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FpcbivPhdWNPrQGt67bnJ%2Fimage.png?alt=media&#x26;token=ee0c41f1-8ba6-485e-8317-ae0f8af44637" alt=""><figcaption></figcaption></figure>

5. Click *Next* and you will be led to the *MongoDB Layout* screen.

Currently, our layout is empty since we have not mapped any fields to it.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FpgUjNfdUjrALUJcDNqlz%2Fimage.png?alt=media&#x26;token=974e94c6-0714-46a0-bfcd-0102175e3e5c" alt=""><figcaption></figcaption></figure>

6. We will map the incoming fields from the *XML/JSON Source* object to the *MongoDB* *Destination* object.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FVxQbydj9WXP2MCT8SFCj%2Fimage.png?alt=media&#x26;token=bfd42e27-19fe-4791-a635-3820884536d4" alt=""><figcaption></figcaption></figure>

7. We will then reopen the *MongoDB Layout* screen.

As you can see below, the entire layout has now been defined.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FKvD4MCLGBVqj9GiCsqqH%2Fimage.png?alt=media&#x26;token=ce5f1f21-2cd4-4060-b9c4-616211e24a86" alt=""><figcaption></figcaption></figure>

8. Click *OK* and the *MongoDB Destination* object will be configured.

Select the *Start Dataflow* option in the main toolbar and the data will be written to the destination.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FNn8usWuNFSk2K4Pxk0jh%2Fimage.png?alt=media&#x26;token=ac204ed9-8154-494d-8624-5882cee34ead" alt=""><figcaption></figcaption></figure>

9. As you can see in the Job Progress window, the data has been successfully written to the destination.

{% hint style="info" %}
**Note:** You can see the acknowledgment in the window since we selected the respective option.
{% endhint %}

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FAXX1ixcNEJwtphqiSn72%2Fimage.png?alt=media&#x26;token=401a2cc2-8a1e-4d13-a810-69af7a90e74d" alt=""><figcaption></figcaption></figure>

This concludes the configuration of the *MongoDB Destination* object in Astera.
