Codota Logo
BulkWriteError.getCode
Code IndexAdd Codota to your IDE (free)

How to use
getCode
method
in
com.mongodb.bulk.BulkWriteError

Best Java code snippets using com.mongodb.bulk.BulkWriteError.getCode (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
DateTime d =
  • Codota Iconnew DateTime()
  • Codota IconDateTimeFormatter formatter;String text;formatter.parseDateTime(text)
  • Codota IconObject instant;new DateTime(instant)
  • Smart code suggestions by Codota
}
origin: org.mongodb/mongo-java-driver

  @Override
  public String toString() {
    return "BulkWriteError{"
        + "index=" + index
        + ", code=" + getCode()
        + ", message='" + getMessage() + '\''
        + ", details=" + getDetails()
        + '}';
  }
}
origin: org.mongodb/mongo-java-driver

static List<BulkWriteError> translateWriteErrors(final List<com.mongodb.bulk.BulkWriteError> errors) {
  List<BulkWriteError> retVal = new ArrayList<BulkWriteError>(errors.size());
  for (com.mongodb.bulk.BulkWriteError cur : errors) {
    retVal.add(new BulkWriteError(cur.getCode(), cur.getMessage(), DBObjects.toDBObject(cur.getDetails()), cur.getIndex()));
  }
  return retVal;
}
origin: org.mongodb/mongo-java-driver

private void mergeWriteErrors(final List<BulkWriteError> newWriteErrors, final IndexMap indexMap) {
  for (BulkWriteError cur : newWriteErrors) {
    this.writeErrors.add(new BulkWriteError(cur.getCode(), cur.getMessage(), cur.getDetails(), indexMap.map(cur.getIndex())
    ));
  }
}
origin: spring-projects/spring-data-mongodb

if (x.getCode() == 11000) {
  return new DuplicateKeyException(ex.getMessage(), ex);
origin: immutables/immutables

List<BulkWriteError> errors = ((MongoBulkWriteException) exception).getWriteErrors();
check(errors).hasSize(1);
check(errors.get(0).getCode()).is(11000);
check(errors.get(0).getMessage()).contains("duplicate key");
return;
origin: org.mongodb/mongo-java-driver

@SuppressWarnings("deprecation")
private MongoException convertBulkWriteException(final MongoBulkWriteException e) {
  BulkWriteError lastError = getLastError(e);
  if (lastError != null) {
    if (ErrorCategory.fromErrorCode(lastError.getCode()) == ErrorCategory.DUPLICATE_KEY) {
      return new DuplicateKeyException(manufactureGetLastErrorResponse(e), e.getServerAddress(),
                         translateBulkWriteResult(e.getWriteResult()));
    } else {
      return new WriteConcernException(manufactureGetLastErrorResponse(e), e.getServerAddress(),
                       translateBulkWriteResult(e.getWriteResult()));
    }
  } else {
    return new WriteConcernException(manufactureGetLastErrorResponse(e), e.getServerAddress(),
                     translateBulkWriteResult(e.getWriteResult()));
  }
}
origin: org.mongodb/mongo-java-driver

private BsonDocument manufactureGetLastErrorResponse(final MongoBulkWriteException e) {
  BsonDocument response = new BsonDocument();
  addBulkWriteResultToResponse(e.getWriteResult(), response);
  if (e.getWriteConcernError() != null) {
    response.putAll(e.getWriteConcernError().getDetails());
  }
  if (getLastError(e) != null) {
    response.put("err", new BsonString(getLastError(e).getMessage()));
    response.put("code", new BsonInt32(getLastError(e).getCode()));
    response.putAll(getLastError(e).getDetails());
  } else if (e.getWriteConcernError() != null) {
    response.put("err", new BsonString(e.getWriteConcernError().getMessage()));
    response.put("code", new BsonInt32(e.getWriteConcernError().getCode()));
  }
  return response;
}
origin: org.springframework.data/spring-data-mongodb

if (x.getCode() == 11000) {
  return new DuplicateKeyException(ex.getMessage(), ex);
origin: org.axonframework/axon-mongo

private static boolean isDuplicateKeyException(Exception exception) {
  return exception instanceof DuplicateKeyException || (exception instanceof MongoBulkWriteException &&
      ((MongoBulkWriteException) exception).getWriteErrors().stream().anyMatch(e -> e.getCode() == 11000));
}
origin: org.axonframework.extensions.mongo/axon-mongo

private static boolean isDuplicateKeyException(Exception exception) {
  return exception instanceof DuplicateKeyException || (exception instanceof MongoBulkWriteException &&
      ((MongoBulkWriteException) exception).getWriteErrors().stream().anyMatch(e -> e.getCode() == 11000));
}
origin: stackoverflow.com

List<String>duplicateIds = new ArrayList<String>();
   List<BulkWriteError> errors = mbwe.getWriteErrors();
   for (BulkWriteError error : errors) {
     LOGGER.error("{}", error.getMessage());
     // extract from error.message the id of the duplicated document, (11000 is the duplicate id code)
     if (error.getCode() == 11000) {
       Matcher m = Pattern.compile("[0-9a-f]{24}")
           .matcher(error.getMessage());
       m.find();
       duplicateIds.add(m.group());
     }
   }
   // here the duplicateIds will hold all the found ids, you can print them in console for example:
   System.out.println(duplicateIds.toString());
   // and do whatever else you like with them
origin: org.mongodb/mongodb-driver-core

  @Override
  public String toString() {
    return "BulkWriteError{"
        + "index=" + index
        + ", code=" + getCode()
        + ", message='" + getMessage() + '\''
        + ", details=" + getDetails()
        + '}';
  }
}
origin: org.mongodb/mongodb-driver

static List<BulkWriteError> translateWriteErrors(final List<com.mongodb.bulk.BulkWriteError> errors) {
  List<BulkWriteError> retVal = new ArrayList<BulkWriteError>(errors.size());
  for (com.mongodb.bulk.BulkWriteError cur : errors) {
    retVal.add(new BulkWriteError(cur.getCode(), cur.getMessage(), DBObjects.toDBObject(cur.getDetails()), cur.getIndex()));
  }
  return retVal;
}
origin: org.mongodb/mongodb-driver-core

private void mergeWriteErrors(final List<BulkWriteError> newWriteErrors, final IndexMap indexMap) {
  for (BulkWriteError cur : newWriteErrors) {
    this.writeErrors.add(new BulkWriteError(cur.getCode(), cur.getMessage(), cur.getDetails(), indexMap.map(cur.getIndex())
    ));
  }
}
origin: SoftInstigate/restheart

if (error.getCode() == 11000 &&
    error.getMessage().contains("_id_ dup key")) {
  nrep.addProperty("index",
      new BsonInt32(
          ResponseHelper.getHttpStatusFromErrorCode(
              error.getCode())));
} else {
  nrep.addProperty("index",
      new BsonInt32(error.getIndex()));
  nrep.addProperty("mongodbErrorCode",
      new BsonInt32(error.getCode()));
  nrep.addProperty("httpStatus",
      new BsonInt32(HttpStatus.SC_NOT_FOUND));
      new BsonString(
          ResponseHelper.getMessageFromErrorCode(
              error.getCode())));
origin: org.opencb.cellbase/cellbase-lib

for (BulkWriteError bulkWriteError : e.getWriteErrors()) {
  if (ErrorCategory.fromErrorCode(bulkWriteError.getCode()).equals(ErrorCategory.DUPLICATE_KEY)) {
    return 0;
origin: opencb/cellbase

for (BulkWriteError bulkWriteError : e.getWriteErrors()) {
  if (ErrorCategory.fromErrorCode(bulkWriteError.getCode()).equals(ErrorCategory.DUPLICATE_KEY)) {
    return 0;
origin: opencb/opencga

      if (!ErrorCategory.fromErrorCode(writeError.getCode()).equals(ErrorCategory.DUPLICATE_KEY)) {
        throw e;
      } else {
Set<String> duplicatedNonInsertedId = new HashSet<>();
for (BulkWriteError writeError : e.getWriteErrors()) {
  if (ErrorCategory.fromErrorCode(writeError.getCode()).equals(ErrorCategory.DUPLICATE_KEY)) {
    String id = newStudy.getIds().get(writeError.getIndex());
    duplicatedNonInsertedId.add(id);
origin: org.mongodb/mongodb-driver-core

@SuppressWarnings("deprecation")
private MongoException convertBulkWriteException(final MongoBulkWriteException e) {
  BulkWriteError lastError = getLastError(e);
  if (lastError != null) {
    if (ErrorCategory.fromErrorCode(lastError.getCode()) == ErrorCategory.DUPLICATE_KEY) {
      return new DuplicateKeyException(manufactureGetLastErrorResponse(e), e.getServerAddress(),
                         translateBulkWriteResult(e.getWriteResult()));
    } else {
      return new WriteConcernException(manufactureGetLastErrorResponse(e), e.getServerAddress(),
                       translateBulkWriteResult(e.getWriteResult()));
    }
  } else {
    return new WriteConcernException(manufactureGetLastErrorResponse(e), e.getServerAddress(),
                     translateBulkWriteResult(e.getWriteResult()));
  }
}
origin: org.mongodb/mongodb-driver-core

private BsonDocument manufactureGetLastErrorResponse(final MongoBulkWriteException e) {
  BsonDocument response = new BsonDocument();
  addBulkWriteResultToResponse(e.getWriteResult(), response);
  if (e.getWriteConcernError() != null) {
    response.putAll(e.getWriteConcernError().getDetails());
  }
  if (getLastError(e) != null) {
    response.put("err", new BsonString(getLastError(e).getMessage()));
    response.put("code", new BsonInt32(getLastError(e).getCode()));
    response.putAll(getLastError(e).getDetails());
  } else if (e.getWriteConcernError() != null) {
    response.put("err", new BsonString(e.getWriteConcernError().getMessage()));
    response.put("code", new BsonInt32(e.getWriteConcernError().getCode()));
  }
  return response;
}
com.mongodb.bulkBulkWriteErrorgetCode

Popular methods of BulkWriteError

  • getIndex
    The index of the item in the bulk write operation with this error.
  • getMessage
  • getDetails
  • <init>
    Constructs a new instance.
  • getCategory
  • toString

Popular in Java

  • Finding current android device location
  • getSharedPreferences (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • setContentView (Activity)
  • Path (java.nio.file)
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now