Morphia save () method - how to determine success or failure
I am using Morphia 0.109 with MongoDB. My document collection uses String values ββfor the _id field, like
@Entity
class MyEntity {
@Id
private String entityId;
...
}
When I call the Datastore or BasicDAO save () method to insert one of these items, I populate the _id (entityId) field with the unique value I require. The save () method returns a Key value.
My question is, how can I tell, from validating the returned key, whether the save operation succeeds or fails? I can't rely on a validation trick to see if Morphia has filled the _id field, since I had to fill it in before calling save ().
source to share
This is because you are using String
instead ObjectId
. Is there a specific reason for this?
In general, use the correct WriteConcern for your situation, which is a trade-off between speed and data security. You will face an exception if your stated requirements cannot be met - for example, forJOURNAL_SAFE
Exceptions are thrown due to network problems and server errors ; the write operation expects the server to group the commit of the log file to disk.
source to share