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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.10.1
    • Fix Version/s: 2.11.0
    • Component/s: API
    • Labels:
      None
    • Environment:
      any mongod version

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: