javamongodbmorphiaodm

Migrate to Mongo Morphia 2


I'm trying to migrate to Mongo Morphia 2. Documentation is very poor. How should I rewrite the following function

return datastore.get(type, id.toUUID());

I've tried this

return datastore.find(type).field("_id_").equal(id.toUUID()).first();

I'm not sure how get(T, String) is mapped. I cannot find documentation on that function. I explored the data on MongoDB, I saw that all indexes have an "id" field.


Solution

  • You'd write something like: datastore.find(type).filter(eq("_id", id.toUUID())).first(). You can also just refer to the name of the java field and Morphia will map that correctly.

    What version are you updating from? That API looks crazy old to me.