Detecting the availability of Atlas Search?

Is there a recommended way to check for the availability of Atlas, for a given connection URL?

Basically we would like to have an operation that takes advantage of Mongo Atlas, for text searching, but falls back to basic text searches when connecting to a local Mongo instance.

If nothing more specific exists, you could check if the URI ends with to determine it is atlas.

I was debating doing this too, but I would need to see how to make the logic available to the model, so I could do something like:


or something equivalent.

Since we are using ‘mongoose’ I asked on StackOverflow as well, and it may be the only realistic approach is via a try/catch.

Essentially what we would is catch the error, check if it corresponds to “Unrecognized pipeline stage name: ‘$search’” and then fallback to a non-Atlas query.

1 Like

Hi @Andre-John_Mas1,

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 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.