如何通过MongoDB Compass连接本地C:MongoDB/data路径下的dataBase数据库?
Connecting to Your Local
dataBase via MongoDB Compass Hey there! Let me walk you through the straightforward steps to connect to your dataBase database stored at C:\MongoDB\data using MongoDB Compass. Here's what you need to do:
Step 1: Ensure MongoDB Service is Running
First things first — Compass connects to a running MongoDB instance, not directly to the disk files. So you need to start the MongoDB server pointing to your data directory:
- Open a command prompt (CMD or PowerShell) as Administrator.
- Run this command:
mongod --dbpath "C:\MongoDB\data" - You’ll see logs indicating the server is running (look for a line like
waiting for connections on port 27017). Leave this window open while using Compass.
Alternatively, if you’ve installed MongoDB as a Windows service, just start it via the Services app:
- Press
Win + R, typeservices.msc, and hit Enter. - Find the MongoDB service (usually named
MongoDB), right-click it, and select Start.
Step 2: Open MongoDB Compass and Configure Connection
- Launch MongoDB Compass. If it’s your first time, you’ll land directly on the connection screen. If not, click the New Connection button in the top-left corner.
- For a default local setup, use the connection string:
Or, fill in the fields manually:mongodb://localhost:27017/- Hostname:
localhost - Port:
27017(this is MongoDB’s default port; change it only if you configured a different one)
- Hostname:
Step 3: Connect and Access Your dataBase
- Click the Connect button. If the server is running correctly, you’ll see a list of all databases on your local instance.
- Look for
dataBasein the left-hand sidebar — click it to explore its collections, view documents, and perform any database operations you need.
Quick Troubleshooting Tips
- If you get a "connection refused" error: Double-check that the MongoDB server is running and using the correct port.
- If
mongodthrows a permission error: Make sure your user account has read/write access toC:\MongoDB\data. - If you don’t see
dataBaselisted: Confirm that the database actually exists (it’s created automatically when you first insert data, but if you haven’t done that yet, it won’t show up until you add collections/documents).
内容的提问来源于stack exchange,提问作者Dominik Domanski
相关产品推荐
相关产品推荐

