We are migrating MongoDB data from AWS ec2 instance to Mongo atlas. We have not created any indexes apart from default index _id in AWS EC2 instances and while running queries in AWS EC2 those queries giving result dataset in less time but after migrating data from AWS EC2 to Mongo Atlas those same queries taking more time than the queries running in AWS EC2 to get result dataset. What could be the reason for this difference between AWS EC2 to Mongo Atlas. Here both versions are same 6.0
What you’re describing is unexpected: assuming your application server is running in the same cloud region as your MongoDB Atlas cluster, I’d expect a <2ms latency hop over the network.
Therefore some ideas
-
Is it possible that the app server is actually running in a different region from the Atlas cluster?
-
Is it possible that the local EC2 case did not have TLS network encryption and/or database authentication enabled? (Note that Atlas requires both TLS network encryption and the SCRAM database authentication which introduces approximately 100ms at connection instantiation time. Importantly this is a “one time” cost – you should re-use the connection in a a connection pool). Maybe there’s a pathological issue where you’re reconnecting on every query instead of re-leveraging an open connection pool?
-
Might you be running queries where something else isn’t apples to apples: e.g. a different data size in MongoDB locally vs MongoDB Atlas, or a different index configuration between the two? (You mentioned only having the _id index, but are you sure you’re running a covered query on the _id field and/or that there isn’t another index?
In addition,
What is the ec2 type ?
What is the Atlas cluster tier ?