I am saving my document in MongoDb and using save method with class,collection name param.
All the methods of save and insert are void return type. then how i can know that my document was saved or not.
Is it that i have to re-query to check whether my document was saved. I just need any return value to see if it was saved.
Moreover i am using Spring Data for Mongo to do operations.
解决方案
It depends on what WriteConcern are you using. If you use WriteConcern.ACKNOWLEDGED,
the operation will wait for an acknowledgement from the primary server, so if no exception is raised, the record has been saved correctly. Otherwise you should be able to query WriteResult
WriteResult writeResult=mycollection.insert(record);
if (writeResult.getError() != null) {
throw new Exception(String.format("Insertion wasn't successful: %s",writeResult));
}