db.collectionB.findOne()
{
"_id" : NumberLong(24),
"class" : "Top",
"type" : DBRef("collectionA", NumberLong(47))
}
db.collectionA.findOne()
{
"_id" : NumberLong(47),
"name" : "John",
"position" : 2
}
形成されるクエリ: db.collectionB.find({type: DBRef("collectionA", NumberLong(47))});
コレクション A とコレクション B には多数のドキュメントがあります。collectionB の type が collectionA の NumberLong(47) のドキュメントを参照しているドキュメントを検索したい。
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);
出力は null になります。なんで?