[JAVA-184] Problem with Relations to Collections with more then 2 dots in the name Created: 11/Oct/10  Updated: 29/Oct/10  Resolved: 12/Oct/10

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.1
Fix Version/s: 2.2

Type: Bug Priority: Major - P3
Reporter: Bernhard Dangl Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

It is possible to create a collection eg. with the name "this.is.a.collection". All works well when doing queries in the mongo-console and with the java-driver as well.
Except a problem in method find() of class DBRef. It always returns null when the referenced collection has a name of form this.is.a.collection.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 12/Oct/10 ]

Great!
Will mark as fixed in 2.2

Comment by Bernhard Dangl [ 12/Oct/10 ]

ServerVersion: 1.6.2
JavaDriver 2.2: with 2.2 it works fine.
JavaDriver 2.1: Problems as described above.

Comment by Eliot Horowitz (Inactive) [ 12/Oct/10 ]

Weird.
Can you try 2.2
What version of server?

Comment by Bernhard Dangl [ 12/Oct/10 ]

the output of the first example:

id of target: 4cb3ffc8e8b8105db3a4f988
id of source: 4cb3ffc8e8b8105db4a4f988
{ "name" : "source" , "target" :

{ "$ref" : "this.is.the.target", "$id" : "4cb3ffc8e8b8105db3a4f988" }

, "_id" : { "$oid" : "4cb3ffc8e8b8105db4a4f988"}}

{ "$ref" : "this.is.the.target", "$id" : "4cb3ffc8e8b8105db3a4f988" }

reference can't be fetched --->: null

output of the second example:

id of target: 4cb3ff5f1ba8105db9e1b78e
id of source: 4cb3ff5f1ba8105dbae1b78e
{ "name" : "source" , "target" :

{ "$ref" : "target", "$id" : "4cb3ff5f1ba8105db9e1b78e" }

, "_id" : { "$oid" : "4cb3ff5f1ba8105dbae1b78e"}}

{ "$ref" : "target", "$id" : "4cb3ff5f1ba8105db9e1b78e" }

reference fetched --->: { "_id" :

{ "$oid" : "4cb3ff5f1ba8105db9e1b78e"}

, "name" : "Target"}

Comment by Eliot Horowitz (Inactive) [ 12/Oct/10 ]

When you run the first program, what do you get?
Seems to work for me

Comment by Bernhard Dangl [ 12/Oct/10 ]

here the same program with a target collection name without dots:

Mongo mongo = new Mongo("localhost");
		DB db = mongo.getDB("myTestDB");
		
		//store to a collection with dots in the name.
		DBCollection collTarget = db.getCollection("target");
		
		//a simple test object. will be the target of the reference
		BasicDBObject targetObject = new BasicDBObject("name", "Target");
		collTarget.save(targetObject);
		
		ObjectId idTarget = (ObjectId)targetObject.get("_id");
		System.out.println("id of target: "+idTarget);
		
		//store to the source object to a separate collection.
		DBCollection collSource = db.getCollection("this.is.the.source");
		
		//as simple as above but with a reference to the targetObject
		BasicDBObject sourceObject = new BasicDBObject();
		sourceObject.append("name", "source");
		sourceObject.append("target", new DBRef(db, "target", idTarget));
		collSource.save(sourceObject);
		
		ObjectId idSource=(ObjectId)sourceObject.get("_id");
		
		System.out.println("id of source: "+idSource);
		
		System.out.println(sourceObject);
		
		//get the relation
		DBRef ref = (DBRef)sourceObject.get("target");
		System.out.println(ref);
		
		//fetch the related object
		System.out.println("reference can't be fetched --->: "+ref.fetch());

this works fine.

Comment by Bernhard Dangl [ 12/Oct/10 ]

Here an example, hope that clarifies a little bit:

                Mongo mongo = new Mongo("localhost");
		DB db = mongo.getDB("myTestDB");
		
		//store to a collection with dots in the name.
		DBCollection collTarget = db.getCollection("this.is.the.target");
		
		//a simple test object. will be the target of the reference
		BasicDBObject targetObject = new BasicDBObject("name", "Target");
		collTarget.save(targetObject);
		
		ObjectId idTarget = (ObjectId)targetObject.get("_id");
		System.out.println("id of target: "+idTarget);
		
		//store to the source object to a separate collection.
		DBCollection collSource = db.getCollection("this.is.the.source");
		
		//as simple as above but with a reference to the targetObject
		BasicDBObject sourceObject = new BasicDBObject();
		sourceObject.append("name", "source");
		sourceObject.append("target", new DBRef(db, "this.is.the.target", idTarget));
		collSource.save(sourceObject);
		
		ObjectId idSource=(ObjectId)sourceObject.get("_id");
		
		System.out.println("id of source: "+idSource);
		
		System.out.println(sourceObject);
		
		//get the relation
		DBRef ref = (DBRef)sourceObject.get("target");
		System.out.println(ref);
		
		//fetch the related object
		System.out.println("reference can't be fetched --->: "+ref.fetch());

Comment by Eliot Horowitz (Inactive) [ 11/Oct/10 ]

Can you send a full example?
Not sure I see/understand problem.

Generated at Thu Feb 08 08:51:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.