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

UUIDs are stored as little endian (should be big endian)

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.0
    • Affects Version/s: None
    • Component/s: Codecs, Configuration
    • Environment:
      MacOS X 10.6 (which implies a little endian x86/64 CPU)

      In python:
      >>> import pymongo
      >>> import uuid
      >>> from pymongo import Connection
      >>> c = Connection('localhost', 27017)
      >>> db = c.test
      >>> db.foo.insert(

      {"python": uuid.UUID("aaf4c61d-dcc5-e8a2-dabe-de0f3b482cd9")}

      )
      ObjectId('4e318fb98f1e81eac4000001')

      In java:
      UUID id = UUID.fromString("aaf4c61d-dcc5-e8a2-dabe-de0f3b482cd9");
      Mongo mongo = new Mongo();
      DB db = mongo.getDB("test");
      DBObject dbo = new BasicDBObject();
      dbo.put("java", id);
      db.getCollection("foo").insert(dbo);

      Result:
      > db.foo.find()

      { "_id" : ObjectId("4e318fb98f1e81eac4000001"), "python" : UUID('aaf4c61ddcc5e8a2dabede0f3b482cd9') } { "_id" : ObjectId("4e318fc12746ac3aa375aee9"), "java" : UUID('a2e8c5dc1dc6f4aad92c483b0fdebeda') }

      (yes, with the patch from SERVER-1201 applied)

      Java seems to serialize/deserialize the UUIDs as little endian according to BSONEncoder.java, line 354

      Changing this would however break a lot of applications out there. However, the python/java incompatibility is really bad, so it should be fixed in my humble opinion...

            Assignee:
            robert.guo@mongodb.com Robert Guo (Inactive)
            Reporter:
            vboivie Victor Boivie
            Votes:
            7 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: