I’m not aware of a more straightforward
isAtlasCluster() check than using a regex match to test if the hostname in the Connection URI ends in
mongodb.net as suggested by @steevej.
However, it would be much more efficient to set a feature flag based on the connection URI when your application is initialised rather than
try/catch within the model on every request (which will add latency of at least one round trip failure for every search request).
I would also note that checking for an Atlas connection is not equivalent to checking if Atlas Search is configured for a collection. If your application requires some initial configuration of search indexes, you may also want to have a more explicit feature flag configured by an app administrator or enabled as part of search index creation.
EDIT: After further reflection on your use case, I realised there are a few more considerations depending on the destination cluster tier:
Overall this feels like complexity that should be covered by prerequisites and set up of your application rather than runtime checks which may cause your application to behave unexpectedly even if the initial deployment seems fine.