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

MongoDB Compass连接Atlas实例报错‘not master and slaveOk=false’求助

Fixing 'not master and slaveOk=false' Error in MongoDB Compass with Atlas

Hey there, let's work through this frustrating error you're getting when trying to connect MongoDB Compass to your Atlas instance. I've run into this exact issue a few times, so here are the most reliable fixes to get you up and running:

  • Double-check your connection string
    Atlas uses replica sets for high availability, so your connection string needs to include the replica set details. Make sure you copied the full connection string from the Atlas console—this includes the mongodb+srv:// prefix (or standard connection string with ?replicaSet=your-replica-set-name at the end). If you truncated any part of it, Compass might try connecting to a secondary node without enabling read access, triggering the error.

  • Enable read preferences in Compass
    Sometimes even with the right connection string, Compass's default settings don't allow reading from secondary nodes. Here's how to fix it:

    1. Open the Compass connection window
    2. Click on Advanced Options
    3. Navigate to the Read Preferences section
    4. Set the Mode to Secondary Preferred or Primary Preferred
      This automatically sets slaveOk=true under the hood, letting you read from secondary nodes if the primary isn't accessible. Alternatively, you can append ?readPreference=secondaryPreferred directly to your connection string.
  • Verify your Atlas cluster status
    Head over to your Atlas console and check if your cluster is in a healthy state. If there was a recent failover or the cluster is still initializing, you might be connecting to a node that's not currently the primary. Wait a few minutes for Atlas to stabilize, or refresh the cluster status page to confirm all nodes are running.

  • Recheck your IP whitelist
    Even if you added your IP earlier, dynamic IPs can change (especially if you're on a home network). Go to the Network Access tab in Atlas and confirm your current public IP is listed. As a quick test, you can temporarily add 0.0.0.0/0 to allow all IPs (just remember to remove this later for security).

Give these steps a try—most of the time, it's either a missing connection string detail or a read preference setting. Let me know if you still hit issues!

内容的提问来源于stack exchange,提问作者J. Pinkman

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:45:23