For using Morphia, the class which has to be persisted to the MongoDB has to be annotated with @Entity and if you have an “id” attribute in the class, then it has to be annotated by @Id. Updating the Todo class definition and annotating with @Entity and @Id we have:

Note that the individual attributes need not be annotated as they are implicitly persisted by Morphia.
The saving of new Todo instance by using Morphia amounts to just 2 lines of code (excluding the creation of Morphia instance and Mongo instance which is generic across all operations):

Note: getDatastore() and other related methods have been created to move the creation Datastore instance to one place. I will update the Maven project so that one can download the complete code and play around.

In update, we need to construct a query to identify the right record to update and then the update operation which has to be performed on the identified record.
For the query part, we want to find out the record with the given ID: