Question

I am using Morphia for MongoDB and was wondering how error handling works in morphia ?

For example, when I am doing a

dao.save(MyEntity)

How do I know for sure that my save was successful ? Is there some kinda exception handling I can do ?

Thank you

Was it helpful?

Solution

On the one had there are exceptions if something goes wrong with the connections. Check the configuration options in https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/MongoClientOptions.java, especially the write concern. Those settings are a trade-off between security and performance (and single instance vs replica set make a difference as well). You'll need to find the best combination for your use case.

On the other hand: If you are doing the initial save (basically an insert and not an update), the server generates and sets the ObjectId. If it is set, the server has saved the document.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top