Skip to main content
← Back to Articles
mcpcursormongodbdatabasesetup2026

MongoDB MCP Server in Cursor IDE: Query Collections & Debug Schemas (2026)

Connect MongoDB to Cursor IDE via MCP and query your collections, inspect schemas, and debug data issues directly while writing code. Works with Atlas and self-hosted MongoDB.

By Web MCP Guide•April 12, 2026•6 min read

The MongoDB MCP server lets Cursor's AI query your collections, inspect document schemas, run aggregation pipelines, and check indexes — all without leaving your editor. Working against MongoDB Atlas or a self-hosted instance, this guide covers the full setup. If your actual bottleneck is full-text search or log search rather than document queries, the Elasticsearch MCP server guide covers that different (and differently-risky) setup instead. And if what you're really building is semantic/vector search rather than document queries against structured collections, the Pinecone MCP server setup is worth a look — it's a purpose-built vector database rather than a document store with vector-search bolted on.

What You Can Do with MongoDB + Cursor MCP

Once connected, you can ask Cursor things like:

  • "What does a sample document from the users collection look like?"

  • "How many orders were placed in the last 7 days in the orders collection?"

  • "Show me the indexes on the products collection"

  • "What's the schema structure of the events collection? Show me 3 example documents"

  • "Find all users where account_status is 'suspended' and show me the first 10"

  • "Run an aggregation to count orders by status for this month"
  • This removes the constant tab-switching between editor and MongoDB Compass, Robo 3T, or the Atlas Data Explorer.

    Prerequisites


  • Cursor IDE v0.40+

  • Node.js 18+

  • MongoDB Atlas account (or self-hosted MongoDB with connection URI)

  • MongoDB connection string
  • Step 1: Get Your MongoDB Connection String

    MongoDB Atlas


    1. Go to your Atlas project → Database → Click Connect
    2. Select Connect your application
    3. Copy the connection string — it looks like:
       mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/
       

    4. Replace <password> with your actual database user password

    Self-Hosted MongoDB


    Your connection string is typically:
    mongodb://username:password@localhost:27017/
    

    Or for a replica set:
    mongodb://username:password@host1:27017,host2:27017/?replicaSet=rs0
    

    Security tip: Create a dedicated read-only database user for MCP access. In Atlas, go to Database Access → Add New Database User and assign the built-in readAnyDatabase role.

    Step 2: Add to Your Cursor mcp.json

    MongoDB maintains an official MCP server. Add it to ~/.cursor/mcp.json:

    {
      "mcpServers": {
        "mongodb": {
          "command": "npx",
          "args": ["-y", "@mongodb-js/mongodb-mcp-server"],
          "env": {
            "MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/"
          }
        }
      }
    }
    

    Replace the connection string with your actual URI.

    Do not commit this file to git. Add .cursor/mcp.json to your .gitignore, or use environment variable interpolation:

    {
      "mcpServers": {
        "mongodb": {
          "command": "npx",
          "args": ["-y", "@mongodb-js/mongodb-mcp-server"],
          "env": {
            "MDB_MCP_CONNECTION_STRING": "${MONGODB_URI}"
          }
        }
      }
    }
    

    This pulls the value from your shell environment variable MONGODB_URI.

    On Windows, use the full npx path if the server doesn't load:

    "command": "C:\\Program Files\\nodejs\\npx.cmd"
    

    Step 3: Restart Cursor and Test

    Quit and reopen Cursor. Then test:

    List the collections in my MongoDB database
    

    Or more specifically:

    Show me a sample document from the users collection
    

    Specifying Your Database

    If your MongoDB instance has multiple databases, specify which one in your prompt or in the connection string:

    mongodb+srv://user:pass@cluster.mongodb.net/my_database_name
    

    Or ask Cursor to list available databases first:

    What databases are available in this MongoDB connection?
    

    Practical Workflows

    Debugging a Data Issue

    I'm getting an error where some user documents don't have the 
    subscription_plan field. Query the users collection and find all 
    documents where subscription_plan is missing or null, then show 
    me a count and 3 example documents.
    

    Writing a Query with Real Schema Context

    I need to write a MongoDB aggregation that shows total revenue by 
    product category for the last 30 days. Show me what the orders 
    collection schema looks like first, then write the aggregation.
    

    Cursor will inspect your actual collection structure and write the aggregation with your real field names.

    Schema Discovery for a New Codebase

    I just inherited this codebase. Show me sample documents from 
    the users, products, and orders collections so I can understand 
    the data model before I start writing code.
    

    Index Analysis

    The product search queries are slow. Show me the current indexes 
    on the products collection and what a typical search query looks like, 
    then recommend what indexes to add.
    

    Multi-Database Setup

    If you work with multiple MongoDB environments:

    {
      "mcpServers": {
        "mongodb-dev": {
          "command": "npx",
          "args": ["-y", "@mongodb-js/mongodb-mcp-server"],
          "env": {
            "MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/dev_db"
          }
        },
        "mongodb-prod": {
          "command": "npx",
          "args": ["-y", "@mongodb-js/mongodb-mcp-server"],
          "env": {
            "MDB_MCP_CONNECTION_STRING": "mongodb+srv://user:pass@prod-cluster.mongodb.net/prod_db"
          }
        }
      }
    }
    

    Specify in your prompt: "Using mongodb-dev, show me the users collection schema"

    Available MongoDB MCP Tools

    The official MongoDB MCP server exposes:

  • mongodb_list_databases — List all databases on the connection

  • mongodb_list_collections — List collections in a database

  • mongodb_find — Query documents with filter, projection, sort, limit

  • mongodb_aggregate — Run aggregation pipelines

  • mongodb_count — Count documents matching a filter

  • mongodb_get_indexes — List indexes on a collection

  • mongodb_get_schema — Infer schema from sample documents

  • mongodb_explain — Get query execution plan for performance analysis
  • Troubleshooting

    "MongoServerError: Authentication failed"
    Your username or password in the connection string is incorrect. Test the connection string in MongoDB Compass or mongosh first to verify it works.

    "MongoNetworkError: connect ECONNREFUSED"
    For self-hosted: MongoDB isn't running, or the port is wrong. For Atlas: check that your IP address is in the Atlas Network Access allowlist.

    "Server starts but find returns no results"
    You may be querying the wrong database. Include the database name in your connection string, or ask: "What collections exist in this database?"

    Atlas IP Whitelist
    For Atlas clusters, add your machine's IP to the Network Access allowlist. For development, you can allow access from anywhere (0.0.0.0/0) — but don't do this in production.

    Reaching for MongoDB because you need a NoSQL model, not because you specifically need MongoDB?
    Worth a beat of consideration before you build against it. If your actual target is AWS and you want first-class data modeling, access-pattern validation, and cost estimation rather than a generic document store, the DynamoDB MCP server setup guide covers a purpose-built AWS tool for exactly that design process — different query model (single-table design vs. flexible documents), so it's a real tradeoff, not a drop-in swap.



    Related Guides


  • Cursor IDE MCP Setup: Complete Guide (2026)

  • DynamoDB MCP Server: Cursor IDE Setup (2026) — a NoSQL alternative on AWS with dedicated data-modeling and migration tools

  • BigQuery MCP Server for Cursor IDE (2026)

  • PostgreSQL MCP Server for Cursor IDE (2026)

  • Elasticsearch MCP Server: Cursor IDE Setup (2026)

  • Prisma MCP Server: Cursor IDE Setup (2026) — for teams running a relational Postgres database alongside MongoDB and comparing tooling

  • Redis MCP Server: Cursor IDE Setup (2026) — the go-to pairing with a document store when a workload also needs a cache or vector index

  • Best MCP Servers for Developers (2026)

  • Related guides