MongoDb slow performance

Hi, I am trying to move my infrastructure from different cloud provider and got stuck on MongoDB performance in Digital Ocean. All my queries take two times more execution time than it should be compare to previous provider and even localhost. I tested it on the same data, no indexes.

I used .explain("executionStats") command to get execution times. The results:

Digital Ocean:

"executionStats": {
  "executionSuccess": true,
  "nReturned": 12,
  "executionTimeMillis": 609,
  "totalKeysExamined": 0,
  "totalDocsExamined": 333969,

Previous provider:

"executionStats": {
  "executionSuccess": true,
  "nReturned": 12,
  "executionTimeMillis": 256,
  "totalKeysExamined": 0,
  "totalDocsExamined": 333969,


`"executionStats": {
  "executionSuccess": true,
  "nReturned": 12,
  "executionTimeMillis": 221,
  "totalKeysExamined": 0,
  "totalDocsExamined": 333969`,

I run these tests multiple times, tried different queries, but DO is always significantly slower. I tried to scale up DO more, but it didn’t help. I use managed MongoDB 4 GB RAM / 2vCPU / 56 GB Disk in Frankfurt. I had similar setup with previous provider.

Any help appreciate it, thank you.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 9, 2024


It sounds like that this could be just network latency, if you were running the statements from the server itself it would explain why you are seeing the same behavior on your localhost and on the Droplet that you’ve just created.

However, if you are running the statements from your local computer to the remote managed database, it would explain the few hundred milliseconds difference.

Basically, the physical distance between your MongoDB server in DigitalOcean’s data center and your current location might be contributing to increased response times. You could try to spin up a Droplet where you would be running your application on, and measure the execution time when running the statements from the Droplet to the Managed Database that are in the same region.

Let me know how it goes!

- Bobby

Update: I tried to test self hosted Mongo on basic Droplet and execution time is solid. Looks like the issue is in managed MongoDB.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel