Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9236

Wrong binary serialization when DuplicateKey occurs

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.3
    • Component/s: Index Maintenance
    • Environment:
      java driver 2.11.0
    • ALL
    • Hide

      1: run code
      import com.mongodb.BasicDBObject;
      import com.mongodb.Mongo;
      import com.mongodb.MongoException.DuplicateKey;
      import com.mongodb.WriteConcern;
      import org.junit.Test;
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;

      import java.net.UnknownHostException;

      /**

      • @author Anton Volokhov
        */
        public class BDBOSerializeUtilsTest {
        private static final Logger log = LoggerFactory.getLogger(
        BDBOSerializeUtilsTest.class);

      @Test
      public void testSerialize() throws UnknownHostException {
      final BasicDBObject object = new BasicDBObject("_id",
      new byte[]

      {1, 2, 3}

      );
      Mongo mongo = new Mongo();
      mongo.setWriteConcern(WriteConcern.ACKNOWLEDGED);
      mongo.getDB("testSerialize").getCollection("test").insert(object);
      mongo.getDB("testSerialize").getCollection("test").insert(object);
      }
      }
      2. Look at the exception message

      Show
      1: run code import com.mongodb.BasicDBObject; import com.mongodb.Mongo; import com.mongodb.MongoException.DuplicateKey; import com.mongodb.WriteConcern; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.net.UnknownHostException; /** @author Anton Volokhov */ public class BDBOSerializeUtilsTest { private static final Logger log = LoggerFactory.getLogger( BDBOSerializeUtilsTest.class); @Test public void testSerialize() throws UnknownHostException { final BasicDBObject object = new BasicDBObject("_id", new byte[] {1, 2, 3} ); Mongo mongo = new Mongo(); mongo.setWriteConcern(WriteConcern.ACKNOWLEDGED); mongo.getDB("testSerialize").getCollection("test").insert(object); mongo.getDB("testSerialize").getCollection("test").insert(object); } } 2. Look at the exception message

      This code throws MongoException.DuplicateKey, as expected. But error message doesn't contain actual key:
      com.mongodb.MongoException$DuplicateKey: E11000 duplicate key error index: testSerialize.test.$id dup key: { : BinData }

      Looks like this "{ : BinData}" comes from the server side. Is it any way to see actual key, that is duplicated? Just BinData is not user-friendly message at all.

            Assignee:
            Unassigned Unassigned
            Reporter:
            gabol Anton V. Volokhov
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: