{"record":{"id":"5b54676a57d2698f","repo":"MyCATApache/Mycat-Server","slug":"not-where-of-sql","errorCode":null,"errorMessage":"not where of sql","messagePattern":"not where of sql","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/backend/jdbc/mongodb/MongoSQLParser.java","lineNumber":221,"sourceCode":"\t\tSQLExpr expr=state.getWhere();\r\n\t\tDBObject query = parserWhere(expr);\r\n\t\t\r\n\t\tBasicDBObject set = new BasicDBObject();\r\n\t\tfor(SQLUpdateSetItem col : state.getItems()){\r\n\t\t\tset.put(getFieldName2(col.getColumn()), getExpValue(col.getValue()));\t\r\n\t\t}\r\n\t\tDBObject mod = new BasicDBObject(\"$set\", set);\r\n\t\tWriteResult result = coll.updateMulti(query, mod);\r\n\t\t//System.out.println(\"changs count:\"+coll.getStats().size());\r\n\t\treturn result.getN();\r\n\t}\r\n\tprivate int DeleteDate(SQLDeleteStatement state) {\r\n\t\tSQLTableSource table=state.getTableSource();\r\n\t\tDBCollection coll =this._db.getCollection(table.toString());\r\n\t\t\r\n\t\tSQLExpr expr=state.getWhere();\r\n\t\tif (expr==null) {\r\n\t\t\tthrow new RuntimeException(\"not where of sql\");\r\n\t\t}\r\n\t\tDBObject query = parserWhere(expr);\r\n\r\n\t\tWriteResult result = coll.remove(query);\r\n\t\treturn result.getN();\r\n\t}\r\n\tprivate int dropTable(SQLDropTableStatement state) {\t\t\r\n\t\tfor (SQLTableSource table : state.getTableSources()){\r\n\t\t\tDBCollection coll =this._db.getCollection(table.toString());\r\n\t\t\tcoll.drop();\r\n\t\t}\r\n\t\treturn 1;\r\n\t\t\r\n\t}\r\n\t\r\n\tprivate int getSQLExprToInt(SQLExpr expr){\r\n\t\tif (expr instanceof SQLIntegerExpr){\r\n\t\t\treturn ((SQLIntegerExpr)expr).getNumber().intValue();\r","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/backend/jdbc/mongodb/MongoSQLParser.java#L203-L239","documentation":"MongoSQLParser.DeleteDate() refuses to translate a SQL DELETE statement into a MongoDB remove() call when the statement has no WHERE clause. The library deliberately forbids unbounded deletes: without a where expression there is no query DBObject to pass to DBCollection.remove(), and executing it would wipe the whole collection. It throws a plain RuntimeException with the message 'not where of sql'.","triggerScenarios":"Executing a DELETE statement without a WHERE clause through MyCat's MongoDB backend, e.g. `DELETE FROM mycollection`. DeleteDate() checks state.getWhere() == null and throws before building the query.","commonSituations":"Developers or tools issuing unconditional DELETEs (cleanup scripts, ORMs generating bulk deletes) against a MongoDB collection via MyCat; migrations expecting MySQL-like behavior where such a statement would at least be explicit; tests that truncate data with bare DELETE statements.","solutions":["Add a WHERE clause to the DELETE statement that identifies the rows/documents to remove (e.g. `DELETE FROM t WHERE _id = ...`).","If the intent is to empty the collection, drop or clear the collection directly in MongoDB instead of routing a bare DELETE through MyCat.","If unfiltered deletes are genuinely required, patch DeleteDate() to throw a clearer IllegalArgumentException or to reject at SQL-parse time with a descriptive message."],"exampleFix":"// before\nDELETE FROM users;\n\n// after\nDELETE FROM users WHERE last_login < '2020-01-01';","handlingStrategy":"validation","validationCode":"String sql = sqlText.trim().toUpperCase();\nif (sql.startsWith(\"DELETE\") && !sql.contains(\"WHERE\")) {\n    throw new IllegalArgumentException(\"Refusing to run DELETE without WHERE against MongoDB backend\");\n}\n// only then hand the statement to the MongoDB-backed connection","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include a WHERE clause in DELETE statements targeting the MongoDB backend.","Ban bare DELETEs in code review / SQL lint rules.","Use explicit collection-truncation tooling rather than DELETE for wiping data."],"tags":["sql","mongodb","delete","missing-where-clause"],"backgroundTag":"missing-required-argument","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}