PUT Mongo Block

The Put block lets you perform data operations such as INSERT, UPDATE, or UPSERT directly to the database based on a specified query and query key. This block is essential for modifying or adding new data entries within MongoDB during dataflow execution in Neo UI.

Example Scenario

Requirement

An airline brand allows customers to redeem loyalty points to book flight tickets for their dependants. However, before redeeming points, the dependants must be added as nominees. The system stores nominee details in a separate MongoDB table, with a maximum limit of five nominees per customer. The system must allow customers to add nominees while ensuring the limit is not exceeded.

Solution

To add nominees, create a dataflow that inserts nominee information into the MongoDB table. Use a PutMongo block. Refer to this example dataflow to understand how it is configured for a given use case. Make sure that you have access to DocDemo org (100737) and access to Neo. In this dataflow, the GET Mongo block initially fetches the available nominees. Subsequently, a PUT Mongo block is utilised to update the nominee. If the number of nominees is fewer than the maximum limit of five, the system permits the addition of the nominee.

Configuring the Put Mongo Block

To configure the Put Mongo block,

  1. From the dataflow canvas, click on the node and select the PUT Mongo block.
  2. In the Block name field, enter the block name.
    Note: Block names cannot contain spaces or special characters, except for underscores (_). Use camelCase or snake_case formatting.
  3. In the Collection Name field, enter the name of the MongoDB collection you want to query.
  4. In the Mode field, choose the mode. The available modes are Insert, Update, and Upsert.
  5. In the Query field, enter the data you want to inject into MongoDB using JavaScript.
  6. (Optional) In the Query Key field, specify the key used to perform the update. The key identifies the specific record in the database that needs to be updated.
  7. (Optional) In the Options field, specify any additional options for the query. These options modify query behavior and how results are returned.
    Note: For information on available options, refer to the MongoDB documentation on options.
  8. Configure the Input execution logic, Cachable feature and define the execution path as per the requirement.
  9. Click Done.
Configuring the Put Mongo block

Configuring the Put Mongo block