@ShawonSaha Welcome to the forum!
This error message indicates the mongo shell is unable to connect to a MongoDB server on the requested IP & port.
How did you upgrade from MongoDB 3.6 to 4.2? If you have existing data, the normal upgrade path between major releases involves upgrading through adjacent major releases (eg 3.6 to 4.0, then 4.0 to 4.2). The final step of each major release upgrade is to explicitly set a Feature Compatibility Version to enable persisting backwards-incompatible data changes.
The MongoDB documentation includes specific instructions for upgrading between versions depending on your deployment type (standalone, replica set, or sharded cluster).
For example, for a standalone server see:
If you have skipped over 4.0 and gone directly from running 3.6 binaries to 4.2, it is likely that your MongoDB server instance will be unable to start without manual intervention.
You can check the MongoDB logs for more info. If you have installed the official MongoDB server package for Ubuntu, the default log location will be /var/log/mongodb/mongod.log. If the MongoDB process isn’t able to start (or unexpectedly shuts down) the last lines in the log file should provide some context.
If you’re not sure how to interpret the log information, please post the relevant lines here. I would start by reviewing the expected upgrade procedures to make sure you have not skipped any essential steps.
Regards,
Stennie