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

Generated ObjectID not unique

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Major - P3 Major - P3
    • None
    • 1.2
    • None
    • None
    • MacOSX 10.6.2 JDK 1.6

    Description

      In a test class the following code

      List<DBObject> users = new ArrayList<DBObject>();
      users.add(new BasicDBObject(userOne.toMap()));
      users.add(new BasicDBObject(userTwo.toMap()));
      users.add(new BasicDBObject(userThree.toMap()));
      repo.getCollection().insert(users);

      produce the same ObjectID for each userXXX inserted

      I see in the driver the "algorithm":
      private static int _nextInc = (new java.util.Random()).nextInt();
      private static int _gentime = _flip( (int)(System.currentTimeMillis()/1000) );

      Suggestion:
      With an "algorithm" like this :

      public static String calculateUniqueId() {
      long number = System.currentTimeMillis() * 1000 + (long) (Math.random() * 1000);
      return Long.toString(number, 25);
      }

      I have ids different for each userXXX in the same test where ObjectID fails

      Attachments

        Activity

          People

            eliot Eliot Horowitz (Inactive)
            desmax Max Dessì
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: