Skip to content
Snippets Groups Projects
Commit 7ff27329 authored by Felipe D'Abrantes's avatar Felipe D'Abrantes
Browse files

Identify more errors when updating/deleting documents

parent fc24d002
No related branches found
No related tags found
1 merge request!25Add a question management page
...@@ -113,8 +113,16 @@ object MongoConnection { ...@@ -113,8 +113,16 @@ object MongoConnection {
val futureResult: Future[UpdateResult] = collection.updateOne(filter, updates).toFuture() val futureResult: Future[UpdateResult] = collection.updateOne(filter, updates).toFuture()
futureResult.map[Unit]((result: UpdateResult) => { futureResult.map[Unit]((result: UpdateResult) => {
if (result.getMatchedCount == 0) {
throw new RuntimeException("No document with the given ID.")
}
if (!result.wasAcknowledged()) { if (!result.wasAcknowledged()) {
throw new RuntimeException("Update was not acknowledged") throw new RuntimeException("Update was not acknowledged.")
}
if (result.getModifiedCount() == 0) {
throw new RuntimeException("No document was modified.")
} }
}) })
} }
...@@ -132,11 +140,11 @@ object MongoConnection { ...@@ -132,11 +140,11 @@ object MongoConnection {
futureResult.map[Unit]((result: DeleteResult) => { futureResult.map[Unit]((result: DeleteResult) => {
if (!result.wasAcknowledged()) { if (!result.wasAcknowledged()) {
throw new RuntimeException("Delete was not acknowledged") throw new RuntimeException("Delete was not acknowledged.")
} }
if (result.getDeletedCount() == 0) { if (result.getDeletedCount() == 0) {
throw new RuntimeException("Delete was not acknowledged") throw new RuntimeException("No document was deleted.")
} }
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment