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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 1.3
    • 1.3
    • None
    • None
    • Major Change

    Description

      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) {
      }
      }

      Attachments

        Activity

          People

            eliot Eliot Horowitz (Inactive)
            lifarv Vladimir Lifar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: