Knowing that the iMac had a built in optical drive and that you’ve tried other discs would have been helpful. Since the computer isn’t reading any of the discs you’ve put in either the problem is the drive or the discs. Software issues are rarely behind CDs and DVDs not mounting. That leaves either the optical drive or the discs. There’s an outside chance that you’ve happened to insert several discs that are dirty or scratched.
Look at the shiny side - the side that faces down when you insert the disc into the computer. If you see lots of scratches or finger prints that could be the problem. You can try cleaning the disc with a soft lint free cloth. Wipe in circles, not back and forth, to remove finger prints. Scratches are more of a problem but you can check out this site - about 2/3 of the way down - for a couple ideas. Before going to all this trouble though, look thru your music/movie collection for a clean unscratched disc and see if it will mount.
If the problem isn’t the disc then it is the drive. Mac internal drives are are slot loaders rather than the tray loader models used by most PC tower manufacturers. Many of us have had lousy luck with them. It is possible the drive’s lens is dirty so getting a lens cleaner is worth the couple dollars they cost. If that doesn’t work and if the Mac is no longer under warranty, don’t bother getting it fixed. Purchase a USB external drive. There’s no such thing as a Mac specific external DVD player - they all work.