if (bucketName.equals("")) {
throw new CollectionException(ErrorCodes.COLLECTION_NAME_EMPTY, "Bucket Name Empty");
}
String result = null;
GridFSDBFile gridFSDBFile = null;
try {
if (!databaseService.getDbList().contains(dbName)) {
throw new DatabaseException(ErrorCodes.DB_DOES_NOT_EXISTS, "DB [" + dbName + "] DOES NOT EXIST");
}
if (_id == null) {
throw new DocumentException(ErrorCodes.DOCUMENT_EMPTY, "File is empty");
}
GridFS gridFS = new GridFS(mongoInstance.getDB(dbName), bucketName);
Object docId = JSON.parse(_id);
BasicDBObject objectId = new BasicDBObject("_id", docId);
gridFSDBFile = gridFS.findOne(objectId);
if (gridFSDBFile == null) {
throw new DocumentException(ErrorCodes.DOCUMENT_DOES_NOT_EXIST, "Document does not exist !");
}
gridFS.remove(objectId);
} catch (MongoException e) {
throw new DocumentException(ErrorCodes.DOCUMENT_DELETION_EXCEPTION, e.getMessage());
}
result = "File [" + gridFSDBFile.getFilename() + "] has been deleted.";
return result;
}