Is there any way to tell if the currently running mongodb is running on Atlas or self-hosted?

If it is Atlas, you want to use Atlas Search, otherwise you want to use legacy search.

For this I need to make sure it is being hosted on Atlas, is there any way?

Hi @1111024,

Welcome to the community :wave:

Do you have further details regarding your use case? E.g. Do you have multiple instances of MongoDB (Both Atlas and self-hosted).

However, depending on your use case and environment, you can attempt to connect with mongosh to a MongoDB deployment and use the Atlas Search $search pipeline stage in an aggregation to determine if the instance you are connected to is hosted on Atlas or not. You should receive the following error if the deployment is self-hosted (not Atlas):

Unrecognized pipeline stage name: '$search'

Regards,
Jason

1 Like

Currently, we are giving users the option to self-deploy the API.

There is a search function in the API, but I want to use Atlas search when I use Atlas.

I don’t think the method you described is bad.

thank you!

1 Like

Hi @1111024,

Another option to consider would be for your application to check the hostname in the MongoDB connection string on startup as a basis for an Atlas Search feature flag. Atlas clusters have hostnames which end in “mongodb.net”.

Regards,
Stennie

2 Likes

That’s a great way!

thank you!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.