Hello Manish! Welcome to the MongoDB community!
What’s the connection URI you’re using in Compass?
For a local MongoDB installation, the URI should be mongodb://localhost:27017.
For Atlas, you can find your connection string by clicking the Connect button under your deployment in the Atlas UI. That’s described in the docs article.