Nected Docs
Try Nected For Free
  • 5 min QuickStart Guide
  • Getting Started
    • Introduction
    • Core Concepts
    • Use Cases
    • Tech Architecture
    • FAQs
  • INTEGRATIONS
    • Overview
    • Integrations Libraries
      • PostGres
      • MySQL
      • Oracle
      • MS SQL Server
      • Snowflake
      • MongoDB
      • RedShift
      • REST API
      • Google Sheets
      • Slack
    • Managing Integrations
  • DATASETS
    • Overview
    • Managing Dataset
  • Rules
    • Overview
    • Rule Types
      • SimpleRule
      • DecisionTable
      • Ruleset
      • Rule Chain
      • Decision Tree
    • Rule Conditions
    • Rule Actions
    • Concepts
      • Rule Result
      • Test & Publish Rules
    • Add Input Attributes
      • JSON Input Attributes
      • List Input Attributes
  • Triggers
    • Trigger Rule via API
    • Trigger Rule via WebHook
    • Trigger Workflow via API
    • Trigger Workflow via WebHook
    • Scheduler
    • Response Format
  • Workflow
    • Overview
    • Managing Workflow
    • Add Node
      • Action Nodes
        • Rule Node
        • Workflow Node
        • Custom Code Node
        • Database Node
        • REST API Node
      • Control Nodes
        • Loop Node
        • Delay Node
        • Response Node
        • Set Variables Node
        • Switch Block
    • Test & Publish Workflows
  • CODE AND DATABASE QUERIES
    • JavaScript Editor
    • Formula Editor
    • JSON Editor
    • List Editor
    • Excel-like Function
  • Embedded System
    • White-Labelling
    • Embeddable View
  • Self Hosting
    • Overview
    • Infrastructure Sizing
    • New Installation
      • Docker
      • Kubernetes
        • Set Up Kubernetes Cluster on AWS EKS
    • Additional Configuration
      • High Availability
      • Email Setup Guide
    • Upgrade Nected Version
  • Security
    • API Authentication
      • OAuth as part of Authentication under REST API
    • Role Based Access Control (RBAC)
    • SOC 2 Type 2, GDPR, ISO Compliance
  • Audit
    • Audit Trail
    • Approval Flow
    • Version Control & Rollback
    • Import/Export
  • Management API
    • Audit Log API
    • Global Variable API
  • References
    • Attribute Library
    • Global Variables
    • Pre-Configured Tokens
    • Pre-Configured Operators
    • NULL Value Handling/Behavior
    • Troubleshooting Errors
      • Multiple Tabs/Users Edits
      • Limits in Nected
    • Allowed Status Combinations
    • Environments
    • Usage Widget
    • Gen AI
  • ACCOUNT SETTINGS
    • Workspace Setting
      • Date Format and Timezone Settings
Powered by GitBook
On this page
  • Integrating MongoDB with Nected
  • Step 1: Add Integration
  • Step 2: Configure Connector Settings
  • Creating MongoDB Data Sources in Nected
  • Supported MongoDB Actions
  • Creating a data source Using No Code Mode
  • Creating a data source Using Code Mode
  • Switching Between No Code and Code Modes
  • Saving Your data source
  • Using MongoDB in Rule & Workflow:
  • Use MongoDB Data to fetch Records in Rule:
  • Trigger MongoDB operations as Rule Actions to Add/Update Records in MongoDB:
  • Trigger MongoDB as a Node to Fetch / Update Records from/to MongoDB in between Workflow:
  • Troubleshooting Common Issues
  1. INTEGRATIONS
  2. Integrations Libraries

MongoDB

PreviousSnowflakeNextRedShift

Last updated 27 days ago

MongoDB is a document-oriented NoSQL database, where data is stored in collections as documents. Unlike relational databases, which store data in rows and columns, MongoDB uses BSON (Binary JSON) format for flexibility and ease of use.

For additional details, please visit the .

This guide provides step-by-step instructions on how to integrate and configure your MongoDB database with Nected, ensuring seamless data interaction within your workflows and rules.

Integrating MongoDB with Nected

To connect your MongoDB database with Nected, follow the steps below carefully.

Step 1: Add Integration

  • Navigate to the Integration Page in Nected.

  • Click on "+ New Integration".

  • Select MongoDB from the available database connectors.

Step 2: Configure Connector Settings

Once you've selected MongoDB integration, configure it by choosing your desired protocol and entering the required details.

Nected provides three methods to connect to your MongoDB database:

1. MongoDB Protocol (Standard Method)

Choose this method if you're connecting directly using your database's IP address and port.

Required Fields:

  • Protocol: Select MongoDB.

  • Host: Enter your MongoDB host IP address (e.g., 127.0.0.1).

  • Port: Enter the port number (default MongoDB port is typically 27017).

  • Username: Your authorized MongoDB username.

  • Password: Your encrypted MongoDB password.

  • Database: The specific MongoDB database to connect to.

2. MongoDB+Srv Protocol (DNS Seedlist Method)

This method uses DNS Seedlist Connection Format (mongodb+srv) for simplified connections without needing a specific port number.

Required Fields:

  • Protocol: Select MongoDB+Srv.

  • Host: Enter your MongoDB host (typically provided by MongoDB Atlas or similar managed services).

  • Username: Authorized MongoDB username.

  • Password: Encrypted MongoDB password.

  • Database: MongoDB database name.

3. Connection String Method

Use this method if you prefer to provide the complete MongoDB connection string directly.

Required Fields:

  • Protocol: Select ConnectionString.

  • Connection String: Paste your complete MongoDB connection string here.

Example:

mongodb+srv://username:password@cluster.mongodb.net/databaseName

Common Additional Settings (for all methods):

  • Enable SSL: Check this box if your MongoDB instance requires SSL/TLS connection.

  • Allowlist IP:

    Ensure that the Nected IP (43.205.43.45) is whitelisted in your MongoDB instance firewall settings to establish a secure and successful connection.

Step 3: Test Connection

After entering your details:

  • Click on "Test Connection".

  • Verify that you receive a confirmation message: "Tested Successfully".

Testing your connection ensures credentials are correct and your database is reachable by Nected.

Step 4: Publish Your Integration

After a successful test:

  • For a Staging environment, click "Publish in Staging".

  • For a Production environment, click "Publish in Production".

Publishing will finalize your configuration and make the database connector available for rule and workflow configurations.

Creating MongoDB Data Sources in Nected

Once you've successfully integrated your MongoDB database with Nected, you can easily create data sources for re-use within your workflows and rules. Nected offers two distinct ways to query MongoDB collections:

This documentation provides a step-by-step explanation of both modes, covering the supported MongoDB actions (find, aggregate, and countDocuments).

Supported MongoDB Actions

Nected supports the following MongoDB operations:

  • Find – Retrieve documents based on filters, projections, sorting, and pagination.

  • Aggregate – Execute complex aggregation pipelines.

  • Count Documents – Count documents matching specific filters.

  • Insert Document – Insert a single document into a collection.

  • Insert Documents – Insert multiple documents simultaneously.

  • Update Document – Update a single document matching specific conditions.

  • Update Documents – Update multiple documents based on filters.

Below you'll find practical examples for common read operations (find, aggregate, and countDocuments). For insert and update operations, follow similar syntax and workflow as guided by the visual UI or MongoDB documentation.

Creating a data source Using No Code Mode

The No Code mode provides a visual query builder for users who prefer a structured, non-technical interface. Follow these steps:

NOTE: MongoDB no code and low-code modes are always in sync.

Steps to Create a data source (No Code)

  1. Navigate to Datasource

    • From the sidebar in Nected, click on Data → Datasource.

    • Click + New Datasource.

  2. Choose your MongoDB Integration

    • Select the integrated MongoDB instance (e.g., Sample_Mongo).

  3. Select the Action

    1. Choose from the dropdown:

    2. Find

    3. Aggregate

    4. Count Documents

    5. Insert Document

    6. Insert Documents

    7. Update Document

    8. Update Documents

  4. Select Collection: Choose the desired MongoDB collection (e.g., movies).

  5. Configure Your Query

    • Use visual inputs to set your filter (Query), the returned fields (Projection), sorting order (Sort), and pagination options (Limit, Skip).

Common Example (Find Action):

  • Action: Find

  • Collection: movies

  • Query:

    { "year": { "$gt": 2000 } }
    
  • Projection:

    { "title": 1, "runtime": 1, "_id": 0 }
    
  • Sort:

    { "runtime": -1 }
    
  • Limit: 5

  • Skip: 0

This example fetches the top 5 movies released after 2000, displaying only their titles and runtimes, sorted by longest runtime first.

Query syntax examples

Data Type

Extended JSON Syntax

Relaxed JSON Syntax

Example

ObjectId

{"FIELD": {"$oid": "VALUE"}}

{"FIELD": ObjectId("VALUE")}

{"_id": {"$oid": "{{Dropdown1.selectedOptionValue[0]}}"}} or {"_id": ObjectId("{{Dropdown1.selectedOptionValue[0]}}")}

Date / ISODate

{"FIELD": {"$date": "YYYY-MM-DDTHH:MM:SSZ"}} or {"FIELD": {"$date": {"$numberLong": "TIMESTAMP"}}}

{"FIELD": ISODate("YYYY-MM-DDTHH:MM:SSZ")}

{"createdAt": {"$date": {"$numberLong": "{{moment.now()}}"}}} or {"createdAt": ISODate("2023-01-01T00:00:00Z")}

Double

{"FIELD": {"$numberDouble": "VALUE"}}

{"FIELD": 123.45}

{"price": {"$numberDouble": "123.45"}} or {"price": 123.45}

Decimal128

{"FIELD": {"$numberDecimal": "VALUE"}}

{"FIELD": NumberDecimal("VALUE")}

{"amount": {"$numberDecimal": "999.99"}} or {"amount": NumberDecimal("999.99")}

Int64

{"FIELD": {"$numberLong": "VALUE"}}

{"FIELD": NumberLong(VALUE)}

{"views": {"$numberLong": "123456789"}} or {"views": NumberLong(123456789)}

Int32

{"FIELD": {"$numberInt": "VALUE"}}

{"FIELD": 42}

{"age": {"$numberInt": "42"}} or {"age": 42}

UUID

{"FIELD": {"$uuid": "UUID_STRING"}}

{"FIELD": UUID("UUID_STRING")}

{"userId": {"$uuid": "123e4567-e89b-12d3-a456-426614174000"}} or {"userId": UUID("123e4567-e89b-12d3-a456-426614174000")}

Creating a data source Using Code Mode

The Code mode allows you to manually input queries using standard MongoDB shell syntax. Follow these instructions for writing queries in Code mode:

Steps to Create a data source (Code Mode)

  1. Navigate to Data → Datasource.

  2. Click + New Datasource and choose your MongoDB integration.

  3. Switch to the Raw (Code) mode.

  4. Write your MongoDB query in standard shell syntax as shown in examples below.

Action Examples:

1. Find Documents

Mongo Shell Syntax:

db.movies.find(
  { "year": { "$gt": 2000 } },
  { "title": 1, "runtime": 1, "_id": 0 }
).sort({ "runtime": -1 }).limit(5)

This retrieves the top 5 movies released after the year 2000, including only titles and runtimes, sorted by longest runtime.

2. Aggregate Documentsx

Mongo Shell Syntax:

db.movies.aggregate([
  { "$match": { "year": { "$gt": 2000 } } },
  { "$group": {
      "_id": "$year",
      "average_runtime": { "$avg": "$runtime" }
    }
  },
  { "$sort": { "average_runtime": -1 } },
  { "$limit": 5 }
])

This query calculates the average runtime of movies released after 2000, groups the result by year, sorts by average runtime descending, and returns the top 5 results.

3. Count Documents

Mongo Shell Syntax:

db.movies.countDocuments(
  { "genres": { "$in": ["Action", "Drama"] } }
)

Returns the total count of documents in the movies collection categorized under "Action" or "Drama" genres.

Switching Between No Code and Code Modes

  • If you begin constructing your query in No Code mode, you can seamlessly switch to Code mode to view the generated MongoDB shell syntax.

  • Switching back from Code mode to No Code mode is supported only when the query uses basic structures that are compatible with visual representation. Complex queries (especially intricate aggregations) might not support switching back.

Saving Your data source

After validating your query results:

  • Click Save data source at the bottom.

  • Provide a descriptive name (e.g., movies_post_2000).

  • Your data source is now ready for use in rules and workflows within Nected.

This structured approach clearly differentiates between No Code and Code modes, offers practical examples, and logically connects each section, making the documentation intuitive for users at all technical skill levels.

Using MongoDB in Rule & Workflow:

Once you’ve created your data source, now you can use the MongoDB in rule and workflow, in the following places:

  1. Rule input

  2. Rule Action

  3. MogoDB node in Workflow

Use MongoDB Data to fetch Records in Rule:

Once your MongoDB integration is successfully configured and data sources are created, you can easily use MongoDB data sources as inputs for rules within Nected.

Select any rule you want to import the MongoDB database and then Follow these steps to trigger it as rule input:

Step 1: Open Input Attribute panel

Click “+Add/Edit Input Attribute” in the Rule configuration panel. From there, open the tab

“Map with Data Source”, where you’ll see an option called “Select data source”.

Step 2: Select the MongoDB data source

Now, when you click on the “Select data source” dropdown, you can see all the data sources you’ve created.

From there, select the data source you want to use as input. (If you’ve not created any data source, then you can create one using the button “Create new Data source”. It will take you to the data source screen, where you can then create the data source using the steps we’ve discussed in the earlier steps.

Once you’re back to the “Map with Data Source” tab, select the data source with you’re relevant version from the versions dropdown and then go to the next step.

Tip 1: If you’ve saved the data source as “draft” (maybe you’ve just created it or saved earlier as draft), in the version dropdown, you can see only one version, i.e. the draft version.

Tip 2: If you’ve multiple published versions, you can change the version you want to use from the dropdown. However, if you want your rule should always use the latest version of the data source, then choose the “Latest Live version” from the dropdown.

Step 3: Fetching the data source columns

Once you’ve integrated the data source, you can add and fetch the columns to use in the rule condition. Follow these steps to do this:

  1. Select the input attribute (if you’ve not created any, then go to the first tab and create one)

  2. Once done, select the attribute, and then select the column name of the data source.

Step 4: Validate and Save

Once mappings are configured, click "Save & Close" to confirm your changes.

Once saved, you can now simply call the attribute inside the rule conditions.

Trigger MongoDB operations as Rule Actions to Add/Update Records in MongoDB:

Not only as a rule input, but you can also use the database as a Rule Action. Here’s how you can add the database in rule action:

First open the rule editor, and then go to the “rule action” section. And then follow the below steps:

  1. Click "Add Action".

  2. Select "MongoDB" from the dropdown.

After selecting the MongoDB datasource, it will open the same editor as you had in while creating the data source.

In rule action, you’ll get the below actions:

  • Insert Document

  • Insert Documents

  • Update Document

  • Update Documents

Configure the settings similarly like you did while creating the data source.

Once configured, click on "Save".

Once done, click "Test Rule" to ensure your MongoDB action performs correctly.

Trigger MongoDB as a Node to Fetch / Update Records from/to MongoDB in between Workflow:

Apart from the rule, you can use MongoDB in the workflow as well.

Select any workflow you want to import the MongoDB database and then Follow these steps to trigger it:

  • Within the workflow canvas, click the "+" (plus) button to add a new node.

  • From the node options, select "Datasource".

  • From the dropdown, choose your integrated MongoDB datasource (e.g., Sample_Mongo).

After selecting MongoDB, configure these settings clearly:

  • Action: Choose the MongoDB operation (Find, Aggregate, Count Documents, Insert Document, Insert Documents, Update Document, Update Documents).

  • Collection: Select your MongoDB collection.

  • Query: Input your MongoDB query in JSON.

  • Projection (optional): Fields you want in the response.

  • Sort (optional): Define the sorting order.

  • Limit (optional): Number of records returned.

  • Skip (optional): Number of records skipped.

  • Connect this MongoDB node appropriately within your workflow logic.

  • Click "Test Workflow" to validate the MongoDB action.

  • After testing, click "Publish" to activate your workflow.

Your MongoDB action node is now configured and ready for execution within your workflow.

Troubleshooting Common Issues

This section outlines common challenges encountered when working with MongoDB data sources in Nected, along with detailed solutions to address them effectively.

1. Connection Failures

  • IP Allowlisting: Ensure IP address 43.205.43.45 (Nected's IP) is allowlisted on your MongoDB instance firewall settings.

  • Authentication: Double-check username/password credentials. Verify roles and permissions assigned to your user.

2. SSL Issues

If SSL/TLS is enabled in your MongoDB instance, ensure that the "Enable SSL" option is checked in Nected.

Confirm that your MongoDB instance SSL certificates are correctly configured and valid.

3. Incorrect Database Name

Enter exact database names (case-sensitive). Verify against MongoDB instance.

4. Incorrect Protocol Selection

5. Invalid Connection String Format

Ensure your connection string follows the standard MongoDB URI format, e.g.:

mongodb+srv://<username>:<password>@<cluster-url>/<database-name>

6. Query Syntax Errors

Queries fail due to incorrect syntax, such as missing brackets, improper use of operators, or malformed JSON.

Solution:

  • Correct Operator Usage: Verify that MongoDB operators (e.g., $gt, $lt, $in) are used appropriately within the query.

  • Field Names: Confirm that field names in the query match exactly with those in the MongoDB collection, considering case sensitivity.

7. Empty Query Results

Queries execute without errors but return no documents.

Solution:

  • Check Filter Criteria: Review the query filters to ensure they match existing documents.

  • Data Types: Ensure that the data types in the query match those in the database (e.g., querying a string field with a numeric value will yield no results).

  • Date Queries: When querying date fields, use the correct date format. For example:

    db.collection.find({ "createdAt": { "$gte": ISODate("2023-01-01T00:00:00Z") } })

    Ensure that the createdAt field is stored as a Date object in MongoDB.

8. Date Handling in Queries

Incorrect date formats lead to unexpected query results or errors.

Solution:

  • Use ISODate: When querying date fields, wrap date strings with ISODate() to ensure correct interpretation:

    db.collection.find({ "date": { "$gte": ISODate("2012-01-01T15:00:00.000Z") } })
  • Alternative JSON Format: In contexts where ISODate() is not recognized (e.g., certain drivers or interfaces), use the extended JSON format:

    { "date": { "$gte": { "$date": "2012-01-01T15:00:00.000Z" } } }
    

    This format is particularly useful in environments that require strict JSON compliance.

9. Aggregation Pipeline Errors

Errors occur when executing aggregation pipelines.

Solution:

  • Pipeline Structure: Ensure that each stage of the pipeline is correctly structured and that the stages are in the correct order.

  • Operator Usage: Verify that aggregation operators (e.g., $match, $group, $project) are used appropriately.

  • Field References: Confirm that all referenced fields exist in the documents and are used correctly within the pipeline stages.

10. Insert and Update Operation Failures

Insert or update operations fail due to schema violations or incorrect data formats.

Solution:

  • Schema Validation: If schema validation is enabled, ensure that the documents conform to the defined schema.

  • Data Types: Verify that the data types of the fields match the expected types in the collection.

  • Required Fields: Ensure that all required fields are present in the documents being inserted or updated.

11. Handling Null or Missing Fields

Issue:

Queries behave unexpectedly when fields are null or missing.

Solution:

  • Existence Checks: Use the $exists operator to check for the presence of fields:

    db.collection.find({ "field": { "$exists": true } })
  • Null Checks: To find documents where a field is null:

    db.collection.find({ "field": null })

Refer to the MongoDB documentation for details:

Learn more about DNS Seedlist (MongoDB+Srv):

More details on connection strings:

(Visual Interface to Write MongoDB Query)

(MongoDB Shell Syntax)

At Nected, we support the query syntax. Here are some examples on referencing certain data types:

Confirm you're using the correct connection method (MongoDB, MongoDB+Srv, ConnectionString) according to your MongoDB deployment. Refer to for clarity.

Validate JSON Structure: Ensure that your query is well-formed JSON. Use tools like to validate.

MongoDB Connection Basics
MongoDB DNS Seedlist Connection Format
MongoDB Connection String URI
No Code
Code
MongoDB Extended JSON (v2)
MongoDB Connection Types
JSONLint
official MongoDB documentation