C# TestContainers and MongoDB Atlas

Hey!

I’m using TestContainers framework for integration testing of MongoDB based service.

private  MongoDbContainer mongoDbContainer = new MongoDbBuilder().Build();
<..>
        public async Task InitializeAsync()
        {
            await mongoDbContainer.StartAsync();
<..>

I ran into an issue when testing the AggregateCommandsAsync command:
MongoDB.Driver.MongoCommandException : Command aggregate failed: $search stage is only allowed on MongoDB Atlas.

Is it possible to setup the Docker container so it would be possible to test Atlas queries?

Thanks in advance.

Hi, @jahru,

$search and $vectorSearch are only available on MongoDB Atlas. You can use the Atlas CLI to spin up local Atlas instances for testing.

Introducing a Local Experience for Atlas, Atlas Search, and Atlas Vector Search with the Atlas CLI

Internally Atlas CLI uses a containerized runtime to host the necessary instances when running local mode clusters. This allows you to develop your Atlas applications without an internet connection and seamlessly deploy to the cloud when you’re ready.

Sincerely,
James

Any plan to support this on the docker version? Creating and destroying an instance MongoDB in Atlas is very slow compared to docker. We have automated integration tests in our CI pipeline that create MongoDB instances automatically and it’s very fast. So far the only thing we can’t test is our search API that uses this search.

Hi, @Francis_Marasigan,

Atlas CLI local mode deploys a containerized Atlas image locally without creating/tearing down a remote Atlas cluster. This local containerized image includes Atlas Search and Atlas Vector Search support. For more information, see the blog post linked above and check out the command line options via:

atlas deployments setup --type local --help

Hope that helps.

Sincerely,
James

I see. I’ll check if we can download the atlas cli in our CI pipeline, then execute command to create instance of atlas mongo. Our CI steps are ephemeral so everything will be dispose once our build and test is completed.