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

Errors when DBRef's $id is Object instead of simple value

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.11.0
    • Affects Version/s: 2.10.1
    • Component/s: API
    • None
    • Environment:
      any mongod version

      Mongo is able to store objects in _id field, for example:
      db.test.save({_id: {name: "Alex", email: "test@example.com"}});

      when i try to make a DBRef from another collection to this record it also works:
      db.test2.save({_id: "test2", ref: new DBRef("test",

      { "name" : "Alex", "email" : "test@example.com" }

      )});
      db.test2.findOne({_id: "test2"}).ref.fetch();

      Same stuff in Java just doesn't work:
      DBCollection test = db.getCollection("test");
      DBCollection test2 = db.getCollection("test2");
      test.save(new BasicDBObject("_id", new BasicDBObject("name", "Alex").append("email", "test@example.com")));
      test2.save(new BasicDBObject("_id", "test2").append("ref", new DBRef(db, "test", new BasicDBObject("name", "Alex").append("email", "test@example.com"))));
      DBObject testOne = test2.findOne(new BasicDBObject("_id", "test2"));
      System.out.println(testOne);

      ...and we got this:
      {
      "_id" : "test2" ,
      "ref" : {
      "$ref" : "test" ,
      "$id" :

      { "name" : "Alex" , "email" : "test@example.com" }

      } ,
      "$id" : {
      "$ref" : "test" ,
      "$id" :

      { "name" : "Alex" , "email" : "test@example.com" }

      }
      }

      as you can see - we've got additional field "$id" that is not in DB!!!
      when we try to use DBRef's in collection - we'll get exception in java side.

            Assignee:
            trisha.gee@10gen.com Trisha Gee
            Reporter:
            mutyonok Oleksii Lomako
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: