// ResultIsNotFound takes a result from an Update/Insert/Delete
// operation and determines from the info if this is a true
// NotFound error.
func ResultIsNotFound(result interface{}) (err error) {
if result == nil {
// If there's no result, we don't know
// what the error should be
return nil
}
switch res := result.(type) {
case *mongo.UpdateResult:
if res.MatchedCount == 0 &&
res.ModifiedCount == 0 &&
res.UpsertedCount == 0 {
err = NotFound
}
case mongo.UpdateResult:
if res.MatchedCount == 0 &&
res.ModifiedCount == 0 &&
res.UpsertedCount == 0 {
err = NotFound
}
case *mongo.BulkWriteResult:
if res.MatchedCount == 0 &&
res.ModifiedCount == 0 &&
res.UpsertedCount == 0 {
err = NotFound
}
case mongo.BulkWriteResult:
if res.MatchedCount == 0 &&
res.ModifiedCount == 0 &&
res.UpsertedCount == 0 {
err = NotFound
}
case *mongo.DeleteResult:
if res.DeletedCount == 0 {
err = NotFound
}
case mongo.DeleteResult:
if res.DeletedCount == 0 {
err = NotFound
}
case *mongo.InsertManyResult:
case mongo.InsertManyResult:
case *mongo.InsertOneResult:
case mongo.InsertOneResult:
case *mongo.SingleResult:
case mongo.SingleResult:
err = nil
default:
// Unrecognized case
err = fmt.Errorf("a type of '%T' was not accounted for in db.IsErrNotFound", res)
logrus.WithFields(logrus.Fields{
"err": err,
}).Errorf("Please check your usage of db.IsErrNotFound")
}
return err
}
I was just wondering if there was a strict mode where a not found could be enforced?