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中“_id”是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);
它使输出为空。为什么?