Workflows
Blocks
Database
MongoDB

MongoDB Database Block

What it does: Connect your workflow to a MongoDB database to store, retrieve, update, and manage your data automatically.

📦

In simple terms: MongoDB stores data as flexible documents (like digital forms) rather than rigid tables. This makes it great for storing varied data like user profiles, product catalogs, or content where each item might have different fields.

When to Use This

Use the MongoDB block when you need to:

  • ✅ Store flexible data that varies between records
  • ✅ Save user profiles with different information per user
  • ✅ Manage product catalogs with varying attributes
  • ✅ Store content or media metadata
  • ✅ Handle nested data structures easily
  • ✅ Scale for large datasets

Example: When a user signs up, store their profile with whatever information they provide - some users have phone numbers, others have social profiles, and MongoDB handles both seamlessly.

Key Features

  • Find Documents: Search and retrieve data using flexible filters
  • Insert Documents: Add new records to your collections
  • Update Documents: Modify existing records with powerful update options
  • Delete Documents: Remove records based on conditions
  • Aggregation: Perform calculations and data analysis
  • Flexible Schema: Store different document structures in the same collection

Setup Guide

Step 1: Connect Your Database

You'll need your MongoDB connection details:

SettingWhat It IsExample
Connection StringFull connection URLmongodb+srv://user:pass@cluster.mongodb.net/mydb
DatabaseThe database namemy_application

MongoDB Atlas Users: Copy your connection string from the Atlas dashboard. Click "Connect" on your cluster and select "Connect your application" to get the connection string.

Step 2: Choose Your Operation

Find: Search for documents matching your criteria

  • Select the collection to search
  • Set filter conditions
  • Choose which fields to return
  • Sort and limit results

Insert: Add new documents

  • Select the target collection
  • Provide document data
  • Insert one or multiple documents

Update: Modify existing documents

  • Set filter to find documents
  • Specify changes to make
  • Update one or many matching documents

Delete: Remove documents

  • Set filter conditions
  • Delete one or many matching documents

Common Use Cases

Store User Profiles

Save detailed user information including preferences, settings, and activity history. Each user can have different fields based on their choices.

Product Catalog Management

Store products with varying attributes - a shirt might have size and color, while electronics have specifications. MongoDB handles both in the same collection.

Content Management

Store articles, blog posts, or media with metadata. Track views, comments, and tags all in one document.

Event and Activity Logging

Record user actions, system events, or transaction logs with timestamps and relevant details.

Session and Cache Storage

Store temporary data like shopping carts, user sessions, or cached responses for quick retrieval.

Working with Collections

Collections in MongoDB are like folders that hold related documents. Common collection patterns include:

CollectionPurposeExample Documents
usersStore user accountsProfile info, settings, preferences
productsProduct catalogItems, prices, descriptions
ordersTransaction recordsOrder details, customer info, items
logsActivity trackingEvents, timestamps, user actions

Filter Basics

When finding or updating documents, use filters to target specific records:

What You WantHow to Filter
Specific userFilter by email or user ID
Active productsFilter where status equals "active"
Recent ordersFilter by order date in last 7 days
High-value customersFilter where total purchases greater than 1000

What You Get Back

After the block runs, you receive:

  • Found Documents: The matching records (for find operations)
  • Insert ID: The unique ID of newly created documents
  • Modified Count: How many documents were updated
  • Deleted Count: How many documents were removed
  • Success/Error Status: Whether the operation completed

Tips for Success

  1. Use meaningful collection names that describe what's stored
  2. Include timestamps in your documents for tracking
  3. Use unique identifiers to easily find specific documents
  4. Keep related data together in the same document when possible
  5. Test your filters with a find operation before running updates or deletes

Troubleshooting

ProblemLikely CauseSolution
Connection failedInvalid connection string or network issuesVerify your connection string and network access
No documents foundFilter doesn't match any recordsCheck your filter conditions
Cannot insertRequired fields missing or duplicate keyVerify document structure
Slow queriesMissing indexes on filtered fieldsAsk your admin to create indexes

Best Practices

  • Use descriptive field names that clearly indicate what data they contain
  • Include created and updated timestamps for tracking changes
  • Store credentials securely using environment variables
  • Handle errors gracefully in your workflow for failed operations
  • Limit result sizes when fetching large datasets to avoid memory issues
Indite Documentation v1.4.0
PrivacyTermsSupport