我有一个类似下面的集合,我想从_id
子文档中获取offerObject
值,我在Spring框架中使用mongoTemplate
。
{
"_id" : ObjectId("543be5f3cbdf2e1eb442cb81"),`
"_class" : "com.mongodb.BasicDBObject",
"offerObject" : {
"_id" : ObjectId("543bbb7ecbdf85c6ceb44f33"),
"type" : "offer"
}
}
有人可以帮我吗?
答案 0 :(得分:0)
我没有使用过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();