MongoDB
Last updated
Last updated
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.
To connect your MongoDB database with Nected, follow the steps below carefully.
Navigate to the Integration Page in Nected.
Click on "+ New Integration".
Select MongoDB from the available database connectors.
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:
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.
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.
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:
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.
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.
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.
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
).
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.
The No Code mode provides a visual query builder for users who prefer a structured, non-technical interface. Follow these steps:
Navigate to Datasource
From the sidebar in Nected, click on Data → Datasource.
Click + New Datasource.
Choose your MongoDB Integration
Select the integrated MongoDB instance (e.g., Sample_Mongo
).
Select the Action
Choose from the dropdown:
Find
Aggregate
Count Documents
Insert Document
Insert Documents
Update Document
Update Documents
Select Collection: Choose the desired MongoDB collection (e.g., movies
).
Configure Your Query
Use visual inputs to set your filter (Query
), the returned fields (Projection
), sorting order (Sort
), and pagination options (Limit
, Skip
).
Action: Find
Collection: movies
Query:
Projection:
Sort:
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.
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")}
The Code mode allows you to manually input queries using standard MongoDB shell syntax. Follow these instructions for writing queries in Code mode:
Navigate to Data → Datasource.
Click + New Datasource and choose your MongoDB integration.
Switch to the Raw (Code) mode.
Write your MongoDB query in standard shell syntax as shown in examples below.
Mongo Shell Syntax:
This retrieves the top 5 movies released after the year 2000, including only titles and runtimes, sorted by longest runtime.
Mongo Shell Syntax:
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.
Mongo Shell Syntax:
Returns the total count of documents in the movies
collection categorized under "Action" or "Drama" genres.
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.
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.
Once you’ve created your data source, now you can use the MongoDB in rule and workflow, in the following places:
Rule input
Rule Action
MogoDB node in Workflow
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:
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”.
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.
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:
Select the input attribute (if you’ve not created any, then go to the first tab and create one)
Once done, select the attribute, and then select the column name of the data source.
Once mappings are configured, click "Save & Close" to confirm your changes.
Once saved, you can now simply call the attribute inside the rule conditions.
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:
Click "Add Action".
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.
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.
This section outlines common challenges encountered when working with MongoDB data sources in Nected, along with detailed solutions to address them effectively.
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.
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.
Enter exact database names (case-sensitive). Verify against MongoDB instance.
Ensure your connection string follows the standard MongoDB URI format, e.g.:
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.
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:
Ensure that the createdAt
field is stored as a Date object in MongoDB.
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:
Alternative JSON Format: In contexts where ISODate()
is not recognized (e.g., certain drivers or interfaces), use the extended JSON format:
This format is particularly useful in environments that require strict JSON compliance.
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.
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.
Issue:
Queries behave unexpectedly when fields are null or missing.
Solution:
Existence Checks: Use the $exists
operator to check for the presence of fields:
Null Checks: To find documents where a field is 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.