t8y2/dbx · error · java.lang.IllegalArgumentException
MongoDB collection '<sourceName>' was not found
Error message
MongoDB collection '<sourceName>' was not found
What it means
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.
Source
Thrown at agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java:1196
MongoCollection<Document> source = database.getCollection(sourceName);
MongoCollection<Document> target = database.getCollection(targetName);
long documentsCopied = cloneCollectionDocuments(source, target, needsValidationBypass(collectionOptions));
long indexesCopied = cloneCollectionIndexes(database, source, sourceName, targetName);
Map<String, Object> result = new LinkedHashMap<>();
result.put("documents_copied", documentsCopied);
result.put("indexes_copied", indexesCopied);
return result;
}
private static Document requireCollectionSpecification(MongoDatabase database, String sourceName) {
for (Document specification : collectionSpecifications(database)) {
if (sourceName.equals(specification.getString("name"))) {
return specification;
}
}
throw new IllegalArgumentException("MongoDB collection '" + sourceName + "' was not found");
}
private static List<Document> collectionSpecifications(MongoDatabase database) {
try {
List<Document> specifications = new ArrayList<>();
for (Document specification : database.listCollections()) {
specifications.add(specification);
}
return specifications;
} catch (RuntimeException error) {
if (isUnsupportedCatalogCommand(error, "listcollections")) {
return legacyCollectionSpecifications(database);
}
throw error;
}
}
private static List<Document> legacyCollectionSpecifications(MongoDatabase database) {View on GitHub (pinned to c0390bff16)
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
Example fix
// before
params.addProperty("database", "prod");
params.addProperty("source_collection", "Order");
// after
boolean exists = db.listCollectionNames().into(new ArrayList<>()).contains("orders");
if (exists) {
params.addProperty("database", "prod");
params.addProperty("source_collection", "orders"); // exact, existing name
params.addProperty("target_collection", "orders_backup");
} Defensive patterns
Strategy: validation
Validate before calling
boolean exists = db.listCollectionNames().into(new ArrayList<>())
.contains(sourceName);
if (!exists) {
throw new IllegalStateException("collection " + sourceName + " does not exist in " + databaseName);
} Type guard
boolean collectionExists(MongoDatabase db, String name) {
return db.listCollectionNames().into(new ArrayList<>()).contains(name);
} Try / catch
try {
agent.execute("cloneCollection", params);
} catch (IllegalArgumentException e) {
if (e.getMessage().endsWith("was not found")) {
log.error("Check database/collection names: {}", e.getMessage());
} else { throw e; }
} Prevention
- Confirm collection existence with listCollectionNames before cloning
- Watch case sensitivity — 'Users' != 'users'
- Log/verify which database the params target in each environment
When it happens
Trigger: 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).
Common situations: Pointing at the wrong environment/database; case-sensitive name mismatch ("Users" vs "users"); collection deleted by another process between planning and execution.
Related errors
- MongoDB aggregate option ${key} must be a non-negative integ
- MongoDB explain verbosity must be queryPlanner, executionSta
- Unsupported findOne option: ${key}
- Unsupported collation option: ${key}
- Invalid collation: locale must not be empty
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/56779d0e4aaa6213.
Report an issue: GitHub.