MQL and ODM (Morphia)

Hello

I saw that Morphia provides a query builder, is it possible to use MQL instead of the query builder?

Something like that (that says deprecated),but for all read/write operations
Aggregate,Update,FindAndModify,Delete etc

https://morphia.dev/morphia/2.1/querying-old.html#_raw_querying

Also why use ODM ? (if i dont want the query builder)
POJO and Mongodb Java driver is harder to use?

Thank you

Morphia predates the driver’s POJO support by several years is the answer for why is there both. Morphia served as the inspiration for the early forms of the driver’s POJO support (though they’ve drifted as such things do). When I first started the POJO support forever ago, my goal was to make it so that the driver supported most needs and for Morphia to be a thin veneer on top. I think that’s probably come to fruition. I think there are still things that Morphia does “better” than the driver but, of course, such things are a matter of taste and preference.

The driver leans more heavily on the BSON types than I prefer but I understand and agree with the reasoning (as best as I understand them no longer being part of the team). Morphia has “better” support for references (whatever your feeling on those may be) and a nicer aggregation API (again with the BSON types). But these are all seriously subjective and i’m clearly biased toward Morphia. Morphia might be “too much” for an application in which case the driver is a perfectly valid and reasonable choice. It just depends on what you need and how you prefer to work.

Using an ODM, whether it’s Morphia or the driver’s POJO support (which Morphia now builds on actually), allows you, as a developer, to work with higher level abstracts (Objects) and let the ODM manage getting data in and out of your domain objects. This simplifies your application and offloads the intricate details of interacting with a driver off to experts who can better manage and track how to do so.

2 Likes

Thank you for the reply,the information,and for Morphia/Java driver.
Morphia is very popular and its looks very nice and clear to me.

I just didn’t know the difference.Also i dont know if we can run a MQL query if it is in Document class of the java driver,or in List of Documents(pipeline)?Morphia supports MQL? Or all queries should be written in its own query builder?

Morphia is not currently set up to accept, say, a json string representing a query as you might write in the shell and execute. I have given some thought to something along those line (along the lines of java.sql.PreparedStatement or hibernate’s named queries, e.g.) but it’s a pretty low priority so far. There are more interesting and significant features and fixes to deal with first. so, yes, the appropriate route with Morphia is via the APIs defined by Query.

2 Likes