db.collectionB.findOne()
{
"_id" : NumberLong(24),
"class" : "Top",
"type" : DBRef("collectionA", NumberLong(47))
}
db.collectionA.findOne()
{
"_id" : NumberLong(47),
"name" : "John",
"position" : 2
}
QUERY to be formed : db.collectionB.find({type: DBRef("collectionA", NumberLong(47))});
There are a number of documents in collection A & collectionB. I want to search the documents where "type" in collectionB is referring to document where "_id" is NumberLong(47) in collectionA.
BasicDBObject query = new BasicDBObject("name","John");
DBObject db_object = findOne("collectionA",query);
DBRef myDbRef = new DBRef(db,"collectionB",db_object);
DBObject doc = myDbRef.fetch();
System.out.println(doc);
It gives the output null. Why?