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?