You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法启动MongoDB:mongod持续处于stop/waiting状态求助

Fixing MongoDB's "stop/waiting" & "Data directory /data/db not found" Error

Hey there, let's work through this MongoDB startup issue together—this is a super common gotcha, so we'll get you sorted quickly.

First, Let's Diagnose the Core Problem

The error exception in initAndListen: 29 Data directory /data/db not found tells us exactly what's going wrong: MongoDB can't locate the directory it needs to store data. This usually happens for one of two reasons:

  1. The default /data/db directory doesn't exist on your system, or
  2. You modified mongod.conf to use a custom data directory, but that directory is missing or has incorrect permissions.

Step 1: Check Your mongod.conf Settings

First, let's confirm what data directory MongoDB is configured to use. Open your config file (typically /etc/mongod.conf on most Linux systems) with this command:

cat /etc/mongod.conf

Look for the storage section—it should look similar to this:

storage:
  dbPath: /data/db
  # Other storage-related settings...

Note the value next to dbPath—that's the directory we need to fix.

Step 2: Create & Secure the Data Directory

If using the default /data/db:

Run these commands to create the directory and grant MongoDB the necessary access (the mongodb system user needs full control over this folder):

# Create the directory (including parent folders if they don't exist)
sudo mkdir -p /data/db

# Set ownership to the mongodb user and group
sudo chown -R mongodb:mongodb /data/db

# Set proper permissions to ensure MongoDB can read/write
sudo chmod 755 /data/db

If using a custom directory from your config:

Replace /your/custom/db/path with the actual path listed in your dbPath setting:

sudo mkdir -p /your/custom/db/path
sudo chown -R mongodb:mongodb /your/custom/db/path
sudo chmod 755 /your/custom/db/path

Step 3: Verify Config File Syntax (Optional but Smart)

If you edited mongod.conf recently, a small typo (like missing YAML indentation or a stray comma) could be causing issues. Check for syntax errors with:

mongod --config /etc/mongod.conf --checkConfig

If the command returns no errors, your config is valid.

Step 4: Restart MongoDB & Check Status

Now restart the service and confirm it's running correctly:

# Restart the MongoDB service
sudo systemctl restart mongod

# Check the service status
sudo systemctl status mongod

You should see active (running) instead of stop/waiting now.

Quick Note About Running mongod Directly

When you run mongod without any arguments, it defaults to /data/db. If your config uses a custom path, you need to tell mongod to use that config file:

mongod --config /etc/mongod.conf

Or specify the data directory directly:

mongod --dbPath /your/custom/db/path

That should resolve the issue! If you still hit problems, double-check that the mongodb user has full access to the data directory—permission issues are the #1 culprit here.

内容的提问来源于stack exchange,提问作者Mortality

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:28:00