docs/docs/data-sources/mongodb.md
ToolJet can connect to MongoDB to read and write data.
<div style={{paddingTop:'24px'}}>To establish a manual connection with the MongoDB data source, click on the + Add new data source button located on the query panel or navigate to the Data Sources page from the ToolJet dashboard.
:::info Please make sure the Host/IP of the database is accessible from your VPC if you have self-hosted ToolJet. If you are using ToolJet cloud, please whitelist our IP. :::
ToolJet requires the following to connect to your MongoDB.
Note: It is recommended to create a new MongoDB user so that you can control the access levels of ToolJet.
You can also use a Connection String by switching the method from the dropdown. You will be prompted to enter the details of your MongoDB connection.
ToolJet requires the following to connect to your MongoDB using Connecting String:
:::info
The connection string typically looks like this: mongodb+srv://${username}:${password}@${cluster}/{database}.
For example: mongodb+srv://tooljettest:[email protected]/hrms
:::
Note: Make sure to replace username, password, cluster, and database with your actual MongoDB details. If your MongoDB instance requires additional connection options, you can usually append these options to the connection string.
</div> <div style={{paddingTop:'24px'}}>:::tip Query results can be transformed using transformations. Read our transformations documentation to see how: link :::
<div style={{paddingTop:'24px'}}>Returns list of collections
Return a document which satisfy the given filter and options. Reference
Return list of documents which satisfy the given filter and options. Reference
Returns an estimation of the number of documents in the collection based on collection metadata. Reference
Returns the number of documents based on the filter. Reference
Retrieve a list of distinct values for a field based on the filter. Reference
Insert a document. Reference
{
"name": "John Doe",
"age": 30
}
Insert list of documents. Reference
[
{
"name": "Product1",
"price": 100
},
{
"name": "Product2",
"price": 150
}
]
Update a document based on the filter. Reference
{
"name": "John Doe"
}
{
"$set": {
"age": 31
}
}
Update many documents based on the filter. Reference
{
"status": "pending"
}
{
"$set": {
"status": "completed"
}
}
Replace a document based on filter. Reference
{
"product_id": 123
}
{
"product_id": 123,
"name": "New Product",
"price": 200
}
If your application requires the document after updating, use this instead of Update One. Reference
{
"employee_id": 456
}
{
"$inc": {
"salary": 5000
}
}
If your application requires the document after updating, use this instead of Replace One. Reference
{
"product_id": 789
}
{
"product_id": 789,
"name": "Updated Product",
"price": 300
}
If your application requires the document after deleting, use this instead of Delete One. Reference
{
"order_id": 101
}
Aggregation operations are expressions you can use to produce reduced and summarized results. Reference
[
{
"$match": {
"status": "completed"
}
},
{
"$group": {
"_id": "$product_id",
"totalSales": {
"$sum": "$amount"
}
}
}
]
Delete a record based on the filter. Reference
{
"user_id": 123
}
Delete many records based on the filter. Reference
{
"status": "cancelled"
}
Perform bulk operations. Reference
[
{
"insertOne": {
"document": {
"item": "apple",
"quantity": 50
}
}
},
{
"updateOne": {
"filter": {
"item": "orange"
},
"update": {
"$set": {
"quantity": 100
}
}
}
},
{
"deleteOne": {
"filter": {
"item": "banana"
}
}
}
]
Dynamic queries in MongoDB can be used to create flexible and parameterized queries.
{ amount: { $lt: '{{ components.textinput1.value }}' }}
// Dates
// supported: Extended JSON syntax
{ createdAt: { $date: '{{ new Date('01/10/2020') }}'} }
// not supported: MongoDB classic syntax
{ createdAt: new Date('01/10/2020') }
Reference on mongodb extended JSON supported data types.
</div> </div>