How can I check the error of Mongodb in Golang?

case 1
if err.Error() == “value is nil”

case 2
if err == mongo.ErrNoDocuments

Methods like cases don’t seem right because you can’t predict what kind of errors will occur. How do I check the error?

1 Like

You can use package variables defined by Mongo Module