{"record":{"id":"56779d0e4aaa6213","repo":"t8y2/dbx","slug":"mongodb-collection-sourcename-was-not-found","errorCode":null,"errorMessage":"MongoDB collection '<sourceName>' was not found","messagePattern":"MongoDB collection '<sourceName>' was not found","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":1196,"sourceCode":"\n        MongoCollection<Document> source = database.getCollection(sourceName);\n        MongoCollection<Document> target = database.getCollection(targetName);\n        long documentsCopied = cloneCollectionDocuments(source, target, needsValidationBypass(collectionOptions));\n        long indexesCopied = cloneCollectionIndexes(database, source, sourceName, targetName);\n\n        Map<String, Object> result = new LinkedHashMap<>();\n        result.put(\"documents_copied\", documentsCopied);\n        result.put(\"indexes_copied\", indexesCopied);\n        return result;\n    }\n\n    private static Document requireCollectionSpecification(MongoDatabase database, String sourceName) {\n        for (Document specification : collectionSpecifications(database)) {\n            if (sourceName.equals(specification.getString(\"name\"))) {\n                return specification;\n            }\n        }\n        throw new IllegalArgumentException(\"MongoDB collection '\" + sourceName + \"' was not found\");\n    }\n\n    private static List<Document> collectionSpecifications(MongoDatabase database) {\n        try {\n            List<Document> specifications = new ArrayList<>();\n            for (Document specification : database.listCollections()) {\n                specifications.add(specification);\n            }\n            return specifications;\n        } catch (RuntimeException error) {\n            if (isUnsupportedCatalogCommand(error, \"listcollections\")) {\n                return legacyCollectionSpecifications(database);\n            }\n            throw error;\n        }\n    }\n\n    private static List<Document> legacyCollectionSpecifications(MongoDatabase database) {","sourceCodeStart":1178,"sourceCodeEnd":1214,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1178-L1214","documentation":"requireCollectionSpecification scans database.listCollections() for the given name and throws when no collection with that exact name exists. cloneCollection validates the source this way before copying, failing fast instead of producing an empty clone.","triggerScenarios":"Calling cloneCollection with a source_collection that does not exist in the specified database (typo, wrong database param, collection dropped earlier, or case mismatch since names are matched exactly).","commonSituations":"Pointing at the wrong environment/database; case-sensitive name mismatch (\"Users\" vs \"users\"); collection deleted by another process between planning and execution.","solutions":["Verify the collection exists with db.getCollectionNames() or listCollections in the target database","Check the 'database' parameter points at the intended database","Fix capitalization — MongoDB names are case-sensitive"],"exampleFix":"// before\nparams.addProperty(\"database\", \"prod\");\nparams.addProperty(\"source_collection\", \"Order\");\n// after\nboolean exists = db.listCollectionNames().into(new ArrayList<>()).contains(\"orders\");\nif (exists) {\n    params.addProperty(\"database\", \"prod\");\n    params.addProperty(\"source_collection\", \"orders\"); // exact, existing name\n    params.addProperty(\"target_collection\", \"orders_backup\");\n}","handlingStrategy":"validation","validationCode":"boolean exists = db.listCollectionNames().into(new ArrayList<>())\n    .contains(sourceName);\nif (!exists) {\n    throw new IllegalStateException(\"collection \" + sourceName + \" does not exist in \" + databaseName);\n}","typeGuard":"boolean collectionExists(MongoDatabase db, String name) {\n    return db.listCollectionNames().into(new ArrayList<>()).contains(name);\n}","tryCatchPattern":"try {\n    agent.execute(\"cloneCollection\", params);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().endsWith(\"was not found\")) {\n        log.error(\"Check database/collection names: {}\", e.getMessage());\n    } else { throw e; }\n}","preventionTips":["Confirm collection existence with listCollectionNames before cloning","Watch case sensitivity — 'Users' != 'users'","Log/verify which database the params target in each environment"],"tags":["mongodb","not-found","validation"],"backgroundTag":"collection-not-found","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}