use of com.mongodb.bulk.BulkWriteError in project zeppelin by apache.
the class MongoNotebookRepo method printDuplicatedException.
/**
* MongoBulkWriteException contains error messages that inform
* which documents were duplicated. This method catches those ID and print them.
* @param e
*/
private void printDuplicatedException(MongoBulkWriteException e) {
List<BulkWriteError> errors = e.getWriteErrors();
for (BulkWriteError error : errors) {
String msg = error.getMessage();
// regex for note ID
Pattern pattern = Pattern.compile("[A-Z0-9]{9}");
Matcher matcher = pattern.matcher(msg);
if (matcher.find()) {
// if there were a note ID
String noteId = matcher.group();
LOG.warn("Note " + noteId + " not inserted since already exists in MongoDB");
}
}
}
use of com.mongodb.bulk.BulkWriteError in project mongo-java-driver by mongodb.
the class WriteCommandResultHelper method getWriteErrors.
@SuppressWarnings("unchecked")
private static List<BulkWriteError> getWriteErrors(final BsonDocument result) {
List<BulkWriteError> writeErrors = new ArrayList<BulkWriteError>();
BsonArray writeErrorsDocuments = (BsonArray) result.get("writeErrors");
if (writeErrorsDocuments != null) {
for (BsonValue cur : writeErrorsDocuments) {
BsonDocument curDocument = (BsonDocument) cur;
writeErrors.add(new BulkWriteError(curDocument.getNumber("code").intValue(), curDocument.getString("errmsg").getValue(), curDocument.getDocument("errInfo", new BsonDocument()), curDocument.getNumber("index").intValue()));
}
}
return writeErrors;
}
Aggregations