Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2108

createIndex command failure on duplicate key incorrectly parses error message

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.14.2
    • Affects Version/s: 2.13.0
    • Component/s: Command Operations
    • None

      When parsing out the error message of a response to creating a unique index, the message will be "errmsg" instead of "err".

      Quick reproduction test case:

         @Test
          public void createIndexErrorMessage() throws Exception {
              final MongoClient client = new MongoClient();
              try {
                  final DBCollection collection = client.getDB("test").getCollection("foo");
                  collection.drop();
                  collection.insert(new BasicDBObject("a", 1));
                  collection.insert(new BasicDBObject("a", 1));
                  collection.createIndex(new BasicDBObject("a", 1), new BasicDBObject("unique", true));
                  fail("should throw");
              } catch (WriteConcernException e) {
                  System.out.println(e.getCommandResult());
                  assertNotNull("didn't find error", e.getErrorMessage());
              } finally {
                  client.close();
              }
          }
          // Output:
          // { "serverUsed" : "127.0.0.1:27017" , "ok" : 0.0 , "errmsg" : "E11000 duplicate key error index: test.foo.$a_1 dup key: { : 1 }" , "code" : 11000}
          // java.lang.AssertionError: didn't find error
      

      Note this does not appear to affect 3.x Java driver versions.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            john.morales@mongodb.com John Morales (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: