{"record":{"id":"31e02898f6524d64","repo":"OtterMind/Chat2DB","slug":"mongodb-count-error","errorCode":"mongodb count error","errorMessage":"mongodb count error","messagePattern":"mongodb count error","errorType":"exception","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDlTemplateServiceImpl.java","lineNumber":348,"sourceCode":"            }\n        } catch (Exception e) {\n            log.error(\"executeUpdate error\", e);\n            throw new BusinessException(\"connection error\", new Object[]{e.getMessage()}, e);\n        }\n        return executeResult;\n    }\n\n    static Long getCountOfMongodb(String tableName, ICommandExecutor executor) {\n        try {\n            SqlExecuteRequest command = new SqlExecuteRequest();\n            command.setTableName(tableName);\n            List<ExecuteResponse> results = executor.executeSelectTable(command);\n            if (CollectionUtils.isEmpty(results)) {\n                return 0L;\n            }\n            return (long) CollectionUtils.size(results.get(0).getDataList());\n        } catch (RuntimeException e) {\n            throw new BusinessException(\"mongodb count error\", new Object[]{tableName, e.getMessage()}, e);\n        }\n    }\n\n}\n","sourceCodeStart":330,"sourceCodeEnd":353,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDlTemplateServiceImpl.java#L330-L353","documentation":"Thrown by the static getCountOfMongodb when a RuntimeException occurs while building and executing an executeSelectTable command to count rows in a MongoDB collection. It wraps the exception with the tableName and the original message. This is a MongoDB-specific count fallback that loads the table and reads dataList size rather than issuing a count command.","triggerScenarios":"Calling count() on a MongoDB datasource (getCountOfMongodb path) where executor.executeSelectTable(command) throws a RuntimeException — collection doesn't exist, connection lost, driver error, or the response is malformed.","commonSituations":"MongoDB collection name typo or already dropped; connection dropped; permissions to read the collection missing; very large collection where loading all rows fails (memory/timeout).","solutions":["Verify the collection (tableName) exists in the MongoDB database.","Inspect the chained cause for the MongoDB driver error.","Check connection health and read permissions.","For very large collections, note this implementation loads all rows to count — consider a native count command if performance is an issue."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Long total = service.count(req);\n} catch (BusinessException e) {\n    if (\"mongodb count error\".equals(e.getCode())) {\n        Object[] args = e.getArgs(); // [tableName, message]\n        // verify collection exists; inspect e.getCause()\n    } else { throw e; }\n}","preventionTips":["Verify the MongoDB collection exists before counting.","Note this implementation loads all rows to count — avoid on huge collections.","Check read permissions on the collection."],"tags":["mongodb","count","wrapper-error"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}