通过Id查询Morphia [英] Querying Morphia by Id
本文介绍了通过Id查询Morphia的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Morphia,MongoDB的Pojo映射器,我觉得很难在我看来应该很简单的任务:通过id获取一个对象。我能够找到集合中的所有对象,但我无法弄清楚使用从列表中获取的ID查询的简单任务。我实际上是在谈论ObjectId。如果我尝试用JSON渲染它,我看到
I am using Morphia, the Pojo mapper for MongoDB, and I find difficult a task that in my view should be very simple: getting an object by id. I am able to find all the objects in a collection but I cannot figure out the simple task of querying using an id I got from the list. I am actually talking about the ObjectId. If I try to render it in JSON I see
推荐答案
这个问题似乎不完整。
您的问题似乎也在于 Morphia快速入门页面。似乎很简单如下。
It also seems like the answer to you question is on the Morphia QuickStart page. Seems to be as simple as follows.
Datastore ds = morphia.createDatastore("testDB");
String hotelId = ...; // the ID of the hotel we want to load
// and then map it to our Hotel object
Hotel hotel = ds.get(Hotel.class, hotelId);
所以你肯定需要更多细节。
So you'll definitely need more details.
这篇关于通过Id查询Morphia的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文