# tCosmosDBOutput

Inserts, updates, upserts or deletes documents in a Cosmos database collection based on the incoming flow from the preceding component in the Job.

This component is not shipped with your Talend Studio by default. You need to install it using the Feature Manager. For more information, see [Installing features using the Feature Manager](https://help.qlik.com/talend/r/en-US/8.0/studio-user-guide/install-features-to-talend-studio).

## tCosmosDBOutput Standard properties

These properties are used to configure tCosmosDBOutput running in the Standard Job framework.

The Standard tCosmosDBOutput component belongs to the Cloud and the Databases families.

The component in this framework is available in all Talend products with Big Data and in Talend Data Fabric.

## Basic settings

| Properties | Description |
| --- | --- |
| Use existing connection | Select this check box and in the Component<br>List drop-down list, select the desired connection component to<br>reuse the connection details you already defined. |
| API | Select the database API to be used. Then the corresponding parameters to be defined are displayed in the Component view.<br><br>In the current version of this component, only the MongoDB API is supported. For this reason, MongoDB database is often mentioned in the documentation of the CosmosDB components. |
| Use replica set address or multiple query routers | Select this check box to show the Server<br>addresses table.<br><br>In the Server addresses<br>table, define the shared MongoDB databases or the MongoDB replica sets<br>you want to connect to. |
| Server and Port | Enter the IP address and listening port of the database<br>server.<br><br>Available when the Use replica set<br>address or multiple query routers check box is not<br>selected. |
| Database | Enter the name of the MongoDB database to be connected to. |
| Set write concern | Select this check box to set the level of acknowledgement requested for write<br>operations. Then you need to select the level of this operation.<br><br>For further information, see the related MongoDB documentation on http://docs.mongodb.org/manual/core/write-concern/. |
| Bulk write | Select this check box to insert, update or remove data in bulk. Note this feature is available only when the version of MongoDB you are using is 2.6+.<br><br>Then you need to select Ordered or Unordered to define how the MongoDB database processes the data<br>sent by Talend Studio.<br><br><ul> <li> <p>If you select <span>Ordered</span>,                  MongoDB processes the queries sequentially.</p> </li> <li> <p>If you select <span>Unordered</span>,                  MongoDB optimizes the bulk write operations without keeping the order in which the                  individual operations were inserted in the bulk write.</p> </li> </ul><br><br>In the Bulk write size field, enter the size of each<br>query group to be processed by MongoDB. In the documentation of MongoDB, some restrictions<br>and expected behaviors as to this size are explained. You can find the details on http://docs.mongodb.org/manual/core/bulk-write-operations/. |
| Authentication mechanism | Among the mechanisms listed on the Authentication mechanism<br>drop-down list, the NEGOTIATE one is recommended if<br>you are not using Kerberos, because it automatically select the authentication mechanism<br>the most adapted to the MongoDB version you are using.<br><br>For details about the other mechanisms in this list, see [MongoDB Authentication](https://docs.mongodb.org/manual/reference/parameters/#param.authenticationMechanisms) from the MongoDB<br>documentation. |
| Set Authentication database | If the username to be used to connect to MongoDB has been created in a specific<br>Authentication database of MongoDB, select this check box to enter the name of this<br>Authentication database in the Authentication database<br>field that is displayed.<br><br>For further information about the MongoDB Authentication database, see [User Authentication database](https://docs.mongodb.org/manual/core/security-users/#user-authentication-database). |
| Username and Password | DB user authentication data.<br><br>To enter the password, click the [...] button<br>next to the password field, enter the password in double quotes in the pop-up dialog box,<br>and click OK to save the settings.<br><br>Available when the Use<br>authentication check box is selected.<br><br>If the security system you have selected from the Authentication mechanism dropdown list is Kerberos, you need to<br>enter the User principal, the Realm and the KDC<br>server fields instead of the Username and the Password<br>fields. |
| Collection | Name of the collection in the database. |
| Drop collection if exist | Select this check box to drop the collection if it already<br>exists. |
| Action on data | The following operations are available:<br><br><ul> <li> <p> <span>Insert</span>: insert documents.</p> </li> <li> <p> <span>Set</span>: modifies the existing fields of an existing                document and appends a field if it does not exist in this document. </p> <p>If you need to apply this action on all the documents in the collection to be                used, select the <span>Update all document</span> check box that                is displayed; otherwise, only the first document is updated.</p> </li> <li> <p> <span>Update</span>: replaces the existing documents with the                incoming data but keeps the technical ID of these documents.</p> </li> <li> <p> <span>Upsert</span>: inserts a document if it does not exist                otherwise it applies the same rules as <span>Update</span>.</p> </li> <li> <p> <span>Upsert with set</span>: inserts a document if it does                not exist otherwise it applies the same rules as <span>Set</span> </p> <p>If you need to apply this action on all the documents in the collection to be                used, select the <span>Update all document</span> check box that                is displayed; otherwise, only the first document is updated.</p> </li> <li> <p> <span>Delete</span>: delete documents.</p> <p>If you need to apply this action on all the documents in the collection to be                    used, selected the <span>Delete all documents</span> check box that is                    displayed, otherwise, only one documented is deleted. </p> </li> </ul> |
| Schema and Edit<br>Schema | A schema is a row description. It defines the number of fields<br>(columns) to be processed and passed on to the next component. When you create a Spark<br>Job, avoid the reserved word line when naming the<br>fields.<br><br><br>Built-In: You create and store the schema locally for this component<br>only.<br><br><br>Repository: You have already created the schema and stored it in the<br>Repository. You can reuse it in various projects and Job designs.<br><br>When the schema to be reused has default values that are<br>integers or functions, ensure that these default values are not enclosed within<br>quotation marks. If they are, you must remove the quotation marks manually.<br><br>For more information, see [Retrieving table schemas](https://help.qlik.com/talend/r/en-US/8.0/studio-user-guide/retrieving-table-schemas?tocId=_C1~eFOlN~GM_JR2qkBYZg).<br><br>Click Edit<br>schema to make changes to the schema. If the current schema is of the Repository type, three options are available:<br><br><ul> <li> <p> <span>View schema</span>: choose this                option to view the schema only.</p> </li> <li> <p> <span>Change to built-in property</span>:                choose this option to change the schema to <span>Built-in</span> for local changes.</p> </li> <li> <p> <span>Update repository connection</span>:                choose this option to change the schema stored in the repository and decide whether                to propagate the changes to all the Jobs upon completion.</p> <p>If you just want to                propagate the changes to the current Job, you can select <span>No</span> upon completion and choose this schema metadata                again in the <span>Repository Content</span>                window.</p> </li> </ul><br><br>Click Sync columns to retrieve the<br>schema from the previous component connected in the Job.<br><br>This component supports dynamic schema when inserting documents to a<br>collection. To use the dynamic schema feature, make sure the schema contains<br>only one column, with the DB column set to<br>\* and Type set to<br>String (if the input type is<br>String) or Object (if the input<br>type is Object).<br><br>Information noteNote:<br><br><ul> <li>The dynamic schema feature is available only when <kbd>Insert</kbd> is selected from the <span>Action on data</span> drop-down list.</li> <li>The dynamic schema feature is available only when you have installed the                           8.0.1-R2022-07 <span>Talend Studio</span> Monthly update or a later one delivered by <span>Talend</span>. For more information, check with your administrator.</li> </ul> |
| Mapping | Each column of the schema defined for this component represents a field of the documents<br>to be read. In this table, you need to specify the parent nodes of these fields, if<br>any.<br><br>For example, in the document reading as<br>follows<br><br>```<br>{<br>_id: ObjectId("5099803df3f4948bd2f98391"),<br>person: { first: "Joe", last: "Walker" }<br>}<br>```<br><br><br>The<br>*first* and the *last*<br>fields have *person* as their parent node but the *\_id* field does not have any parent node. So once completed, this<br>Mapping table should read as<br>follows:<br><br>```<br>Column     Parent node path<br>_id<br>first       "person"<br>last        "person"<br>```<br><br>Not available when the Generate JSON<br>Document check box is selected in Advanced settings. |
| Die on error | This check box is cleared by default, meaning to skip the row on error<br>and to complete the process for error-free rows. |

## Advanced settings

| Properties | Description |
| --- | --- |
| Generate JSON Document | Select this check box for JSON configuration:<br><br><br>Configure JSON Tree: click the<br>[...] button to open the interface<br>for JSON tree configuration. For more information, see [Configuring a JSON Tree](https://help.qlik.com/talend/en-US/components/8.0/processing/configuring-a-json-tree).<br><br><br>Create empty element if<br>needed: If the Related Column in the XML tree editor has null values, or if no<br>column is associated with the XML node, this option creates an open/close tag<br>in the expected place. This check box is selected by default.<br><br><br>Ignore service attributes for empty<br>elements: Select this option to prevent the component from<br>generating a node if the input node is null but has service attributes (such as<br>@type, @class, and @array). This option<br>is available when the Create empty element if<br>needed option is not selected.<br><br><br>Group by: click the [+] button to add lines and choose the input<br>columns for grouping the records.<br><br><br>Remove root node: select this check<br>box to remove the root node.<br><br><br>Data node and Query node (available for update and upsert actions):<br>type in the name of data node and query node configured on the JSON<br>tree.<br><br>These nodes are mandatory for update and upsert actions. They are<br>intended to enable the update and upsert actions though will not be<br>stored in the database.<br><br>Node (available for Set and<br>Upsert with set actions): specify the update operations<br>for specific JSON nodes. To add an update operation, click the plus button at<br>the bottom of this field, enter the update operator or select the update<br>operator from the drop-down list in the Node type<br>column, and enter the node name in double quotation marks in the<br>Node reference column. See [Update Operators](https://docs.mongodb.com/v4.4/reference/operator/update/) for information about update<br>operators.<br><br>Information noteNote: This field is available only when you have installed the<br>R2022-01 Talend Studio Monthly update or a later one delivered by Talend. For more information, check with your administrator. |
| No query timeout | Select this check box to prevent MongoDB servers from stopping idle<br>cursors at the end of 10-minute inactivity of these cursors. In this<br>situation, an idle cursor will stay open until either the results of<br>this cursor are exhausted or you manually close it using the<br>cursor.close() method.<br><br>A cursor for MongoDB is a pointer to the result set of a query. By<br>default, that is to say, with this check box being clear, a MongoDB<br>server automatically stops idle cursors after a given inactivity period<br>to avoid excess memory use. For further information about MongoDB<br>cursors, see https://docs.mongodb.org/manual/core/cursors/. |
| tStatCatcher Statistics | Select this check box to collect the log data at the component<br>level. |

## Usage

| Usage guidance | Description |
| --- | --- |
| **Usage rule** | tCosmosDBOutput executes the action<br>defined on the collection in the database based on the flow<br>incoming from the preceding component in the Job. |
| Limitation | <ul> <li> <p>The "multi" parameter, which allows to update multiple                                        documents at a time, is not supported. Therefore, if two                                        documents have the same key, the first is always updated,                                        but the second never will.</p> </li> <li> <p>For the update operation, the key cannot be a JSON                                        array.</p> </li> </ul> |