DBCollection.save() doesn't throw duplicate key exception

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 1.3
    • Affects Version/s: 1.3
    • Component/s: None
    • None
    • None
    • Major Change
    • None
    • None
    • None
    • None
    • None
    • None

      Steps to reproduce:
      1) create unique index:
      test.ensureIndex(new BasicDBObject("field", 1), "fieldIndex", true);
      2) save object

      {field : 1, d : 1}

      3) save object

      {field : 1, d : 2}

      Expected: exception on step 3
      Detected: no exception. first object stored in DB.

      Unit test:
      @Test
      public void testUniqueViolation() throws UnknownHostException {
      Mongo mongo = new Mongo();
      mongo.dropDatabase("testdb");
      DB db = mongo.getDB("testdb");
      DBCollection test = db.getCollection("test");
      test.ensureIndex(new BasicDBObject("field", 1), "fieldIndex", true);

      test.save(new BasicDBObject("field", 1).append("discriminator", 1));
      try

      { test.save(new BasicDBObject("field", 1).append("discriminator", 2)); Assert.fail(); }

      catch (MongoException e) {
      }
      }

            Assignee:
            Eliot Horowitz (Inactive)
            Reporter:
            Vladimir Lifar
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: