如何在java中从mongodb的子文档中查找_id值
我有一个类似下面的集合,我想从如何在java中从mongodb的子文档中查找_id值,java,mongodb,Java,Mongodb,我有一个类似下面的集合,我想从offerObject子文档中获取\u id值,我在Spring框架中使用mongoTemplate { "_id" : ObjectId("543be5f3cbdf2e1eb442cb81"),` "_class" : "com.mongodb.BasicDBObject", "offerObject" : { "_id" : ObjectId("543bbb7ecbdf85c6ceb44f33"), "type" : "off
offerObject
子文档中获取\u id
值,我在Spring框架中使用mongoTemplate
{
"_id" : ObjectId("543be5f3cbdf2e1eb442cb81"),`
"_class" : "com.mongodb.BasicDBObject",
"offerObject" : {
"_id" : ObjectId("543bbb7ecbdf85c6ceb44f33"),
"type" : "offer"
}
}
有人能帮我吗?我没有使用MongoTemplate,但是根据以前使用Mongo进行java编程的经验,它看起来像这样:
// Pull a document from the Collection
MongoDummyObject mdo = yourTemplate.findOne(query, MongDummyObject.class);
// Get the offer Object from the MongoDummyObject
OfferObject offerObject = mdo.getOfferObject();
// Pull the id from the offer object
String id = offerObject.getId();