Skip to content

Datasource MongoDB

This document provides step-by-step instructions for connecting MongoDB to your web application using both MongoDB Compass and a data integration platform.


Prerequisites

Before connecting to MongoDB, ensure you have:

  • MongoDB Compass installed (for GUI management).
  • Valid connection credentials (username, password, host, port).

MongoDB Compass Setup

This section covers the complete MongoDB setup using MongoDB Compass, including creating connections, databases, collections, and importing data.

Step 1: Create Connection in MongoDB Compass

1.1 Launch MongoDB Compass

  1. Open MongoDB Compass application.

  2. You’ll see the Welcome screen with options for My Queries, Data Modeling, and the Connections panel.

    mongodb

1.2 Add New Connection.

  1. Click the “Add new connection” button (green button in the Connections panel).

    mongodb

  2. The New Connection dialog will appear.

    mongodb

1.3 Configure Connection String

You can connect using the Connection String URL format:

mongodb://[username]:[password]@[host]:[port]/[database]?authSource=[authSource]

Example:

mongodb://myuser:*****@138.201.254.240:8120/foodApp?authSource=admin

Connection Parameters:

  • Username: myuser
  • Password: Your secure password
  • Host: 138.201.254.240
  • Port: 8120
  • Database: foodApp (optional in connection string)
  • Auth Source: admin (authentication database)

mongodb

1.4 Connection Settings

Fill in the following fields:

  • URL: Your complete MongoDB connection string.
  • Name: A friendly name for this connection (e.g., “Demo”).
  • Color: Optional color coding for organization.
  • Favorite: Check to pin connection to top of list.

1.5 Establish Connection

  1. Click “Save & Connect” to save and establish connection.
  2. Or click “Connect” to connect without saving.
  3. Wait for the success notification: “Connected to Demo”.

1.6 Verify Connection

After successful connection, you should see:

  • Your connection listed in the Connections panel with count: CONNECTIONS (1).

  • Available default databases: admin, config, local.

  • Success message at the bottom: ”✓ Connected to Demo”.

    mongodb


Step 2: Create Database and Collection

2.1 Create New Database

  1. Locate your connected server in the left panel: Demo

  2. Hover over the connection name and click the ”+“(Create Database) button that appears

    mongodb

  3. In the “Create Database” dialog, enter:

    • Database Name: foodApp

    • Collection Name: swiggy

      mongodb

2.2 Verify Database Creation

After creation, you should see:

  • New database foodApp in the left panel under your connection

  • Collection swiggy nested under the foodApp database

  • Database hierarchy: DemofoodAppswiggy

    mongodb


Step 3: Import Data to Collection

3.1 Import CSV File

  1. Click the “ADD DATA” dropdown button (green button) and select “Import JSON or CSV file”.

  2. Alternative: Click the “Import data” button in the center of the empty collection view and select your CSV file from your local machine.

    mongodb

  3. In the Import dialog, verify the destination collection (for example, foodApp.swiggy).

  4. Click the file selection area and choose your CSV file (for example, SwiggyData.csv).

  5. Confirm that the filename appears as Import file: SwiggyData.csv.

    mongodb

Field Type Selection:

  • Each field has checkboxes to include/exclude
  • Dropdown to select data type (String, Number, Int32, etc.)
  • Preview of sample data shown for verification

3.2 Execute Import

  1. Click “Import” button (green button at bottom right).

  2. Wait for the import process to complete.

  3. Success notification will appear: ”✓ Import completed. 100 documents imported.”

    mongodb


Web Application Integration

Now that you have set up MongoDB Compass with your data, you can integrate it with your web application.

Step 4: Configure Data Source in Web Application

Access Data Source Panel

  1. Navigate to your web application’s admin panel.

  2. Go to Master DataDatasource.

    mongodb

  3. Click “Create” button.

    mongodb

Select MongoDB Connection

  1. Click on the “MongoDB” option from the data source types.

    mongodb

  2. Fill in the MongoDB Database Connection form:

    Display Name: foodApp
    Connection URL: mongodb://138.201.254.240:8120/foodApp?authSource=admin
    Username: myuser
    Password: ******
    Wait Time: 0
    Is JNDI: False
    Class: mongodb.jdbc.MongoDriver
    Extra Configuration: {}

    mongodb

  3. Click “TEST CONNECTION” to verify.

  4. Upon success, you’ll see “Connection Successfully” message.

    mongodb

  5. Click “SAVE” to store the configuration

Step 5: Create Dataset and Choose Data Source Type

  1. Return to the Datasource list page, verify that your MongoDB connection (foodApp) is listed, select it, and click the “Create Dataset” button.

    mongodb

  2. Click on the “NoSQL” option (highlighted with blue border)

    mongodb

5.1 Upload or Select Files

Choose between two tabs:

  • Upload New Files - Upload fresh data files
  • Select Existing Files - Use already configured collections ✓
  1. Click the “Select Existing Files” tab

    mongodb

  2. This allows you to work with existing MongoDB collections

5.2

  1. Enter dataset name in the field at top: foodAppSwiggy
  2. Default name format: Dataset_67622 (auto-generated)
  3. Use a descriptive name that reflects the data purpose

Step 6: Write MongoDB Query

6.1 Access Query Editor

In the Create Dataset interface, you’ll see:

  • Top toolbar with data source type icons (Existing Connections, Excel, CSV, JSON, Parquet, NoSQL, etc.)

  • The left panel shows the Database section with your connection (foodApp), while the main panel displays the MongoDB Query Editor.

    mongodb

6.2 Example MongoDB Queries

The query editor provides example queries:

// Example MongoDB Query for NoSQL connection
// -- Find all documents in a collection
db.collection_name.find({})
// -- Find with filter: db.collection_name.find({field: value})
// -- Find with projection: db.collection_name.find({}, {field1: 1, field2: 1})

6.3 Write Your Query

Common queries for your swiggy collection:

1. Find All Documents:

db.swiggy.find({})

2. Find with Filter (Rating >= 4):

db.swiggy.find({ Rating: { $gte: 4 } })

3. Find by Area:

db.swiggy.find({ Area: "Central Abohar" })

4. Sort by Rating (Descending):

db.swiggy.find({}).sort({ Rating: -1 })

5. Limit Results:

db.swiggy.find({}).limit(10)

6.4 Test and Save Query

  1. Write your MongoDB query in the editor.
  2. Click “Preview Result” button to test the query.
  3. Review the output to ensure it returns expected data.
  4. Click “Save” button to store the dataset configuration.
  5. Or click “Cancel” to discard changes.

6.5 Additional Options

  • Output Columns: Click to view/modify which columns are included
  • Dataset name shown at top: foodAppSwiggy