Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| Rule( |
| 9 | id="mongodb.connection_refused", |
| 10 | tool="mongodb", |
| 11 | title="MongoDB connection refused", |
| 12 | why="The application could not connect to MongoDB — typically nothing is listening on port 27017.", |
| 13 | checks=( |
| 14 | "Is MongoDB running?", |
| 15 | "Is port 27017 listening?", |
| 16 | "Is MONGODB_URI / connection string correct?", |
| 17 | ), |
| 18 | fixes=( |
| 19 | "docker compose up -d mongo", |
| 20 | "Or start mongod locally", |
| 21 | "Verify the connection URI host and port", |
| 22 | ), |
| 23 | patterns=( |
| 24 | Pattern("ECONNREFUSED", kind="exact", required=True), |
| 25 | Pattern("27017", kind="exact", required=True), |
| 26 | ), |
| 27 | confidence="high", |
| 28 | secondary=("mongo", "connect"), |
| 29 | ), |
| 30 | Rule( |
| 31 | id="mongodb.server_selection", |
| 32 | tool="mongodb", |
| 33 | title="MongoDB server selection failed", |
| 34 | why="The driver could not select a MongoDB server within the timeout " |
| 35 | "(down, wrong URI, or network/TLS issues).", |
| 36 | checks=( |
| 37 | "Is the cluster reachable?", |
| 38 | "Is the connection string correct (host, replicaSet, TLS)?", |
| 39 | "Are IP allowlists / firewall rules blocking you?", |
| 40 | ), |
| 41 | fixes=( |
| 42 | "Verify MongoDB is up and the URI is correct", |
| 43 | "Check Atlas Network Access / IP allowlist if using Atlas", |
| 44 | ), |
| 45 | patterns=( |
| 46 | Pattern("MongoServerSelectionError", kind="exact", required=True, weight=8), |
| 47 | ), |
| 48 | confidence="high", |
| 49 | secondary=("timed out", "connect", "mongo"), |
| 50 | ), |
| 51 | Rule( |
| 52 | id="mongodb.auth_failed", |
| 53 | tool="mongodb", |
| 54 | title="MongoDB authentication failed", |
| 55 | why="Username/password or auth database is incorrect for the MongoDB deployment.", |
| 56 | checks=( |
| 57 | "Are username and password correct?", |
| 58 | "Is authSource set correctly (often admin)?", |
| 59 | "Does the user exist for that database?", |
| 60 | ), |
| 61 | fixes=( |
| 62 | "Update credentials in the connection string", |
| 63 | "Confirm authSource matches where the user was created", |
| 64 | ), |
| 65 | patterns=( |
| 66 | Pattern( |
| 67 | r"Authentication failed|MongoServerError: Authentication failed|" |
| 68 | r"auth failed|codeName: 'AuthenticationFailed'", |
| 69 | kind="regex", |
| 70 | required=True, |
| 71 | ), |
| 72 | Pattern( |
| 73 | r"mongo|Mongo", |
| 74 | kind="regex", |
| 75 | ), |
| 76 | ), |
| 77 | confidence="high", |
| 78 | ), |
| 79 | Rule( |
| 80 | id="mongodb.duplicate_key", |
| 81 | tool="mongodb", |
| 82 | title="Duplicate key error (E11000)", |
| 83 | why="An insert/update violated a unique index — a document with that key already exists.", |
| 84 | checks=( |
| 85 | "Which field/index is unique?", |
| 86 | "Is the application retrying an insert that already succeeded?", |
| 87 | ), |
| 88 | fixes=( |
| 89 | "Use upsert or handle the duplicate in application logic", |
| 90 | "Remove/change the conflicting document or unique value", |
| 91 | ), |
| 92 | patterns=( |
| 93 | Pattern( |
| 94 | r"E11000|duplicate key error", |
| 95 | kind="regex", |
| 96 | required=True, |
| 97 | ), |
| 98 | ), |
| 99 | confidence="high", |
| 100 | secondary=("mongo", "index"), |
| 101 | ), |
| 102 | Rule( |
| 103 | id="mongodb.connection_timeout", |
| 104 | tool="mongodb", |
| 105 | title="MongoDB connection timeout", |
| 106 | why="Connecting to MongoDB timed out before a successful handshake.", |
| 107 | checks=( |
| 108 | "Is the host reachable from this network?", |
| 109 | "Is TLS/SSL required but misconfigured?", |
| 110 | "Is the timeout too low?", |
| 111 | ), |
| 112 | fixes=( |
| 113 | "Check network path to MongoDB", |
| 114 | "Increase serverSelectionTimeoutMS if appropriate", |
| 115 | "Verify TLS options in the URI", |
| 116 | ), |
| 117 | patterns=( |
| 118 | Pattern( |
| 119 | r"connection timed out|MongoNetworkTimeoutError|" |
| 120 | r"Server selection timed out|timed out after \d+ ms", |
| 121 | kind="regex", |
| 122 | required=True, |
| 123 | ), |
| 124 | Pattern( |
| 125 | r"mongo|Mongo|27017", |
| 126 | kind="regex", |
| 127 | ), |
| 128 | ), |
| 129 | confidence="high", |
| 130 | ), |
| 131 | Rule( |
| 132 | id="mongodb.not_primary", |
| 133 | tool="mongodb", |
| 134 | title="MongoDB not primary", |
| 135 | why="A write was sent to a secondary node that is not primary.", |
| 136 | checks=( |
| 137 | "Are you connected to a secondary?", |
| 138 | "Is there a replica set election in progress?", |
| 139 | ), |
| 140 | fixes=( |
| 141 | "Connect to the primary or use a replica set URI", |
| 142 | "Retry after election completes", |
| 143 | ), |
| 144 | patterns=( |
| 145 | Pattern( |
| 146 | r"not primary|NotWritablePrimary|not master", |
| 147 | kind="regex", |
| 148 | required=True, |
| 149 | ), |
| 150 | Pattern( |
| 151 | r"mongo|Mongo", |
| 152 | kind="regex", |
| 153 | ), |
| 154 | ), |
| 155 | confidence="high", |
| 156 | ), |
| 157 | ] |