High RPU/WPU with Atlas Serverless and Mongoose

Hi Team, this post will hopefully save someone time if they encounter the same issue I did.

I recently moved my app onto a Serverless cluster and started seeing high RPU / WPU stats under the monitoring of the cluster in Atlas.

This was strange because no one was using my app. I contacted support who confirmed that this was unexpected for a cluster that wasn’t meant to be doing any work. Even disconnecting my app completely from Atlas and blocking all network traffic didn’t resolve the issue. Only dropping the DB, or more specifically, the TTL index on one of my collections, stopped the high RPU/WPU usage.

It turns out the culprit appears to be the way my Schema is configured in Mongoose…

Bad:

createdAt: {type: Date, default: Date.now, expires: 86400}

Good:

createdAt: {type: Date, default: Date, expires: 86400}

After chaning Date.now to Date, my WPU is basically zero per second when the app isn’t doing anything, while RPU is sitting at about 8/s.

Using Date.now somehow causes Atlas to do some kind of endless loop???
Using Date seems to work just fine.

It would be interesting if someone can explain why this is a problem in Atlas Serverless.
I only picked it up because I noticed my billing was much higher than expected so I’m not sure if this is also a problem in my dev environment, but I simply never noticed.

Cheers, Daniel.

Hi,
My name is Vishal and I work as a Product Manager in MongoDB Atlas Serverless team. The code snippet you posted seems to be creating a TTL index which automatically deletes your document based on the expires flag. TTL indexes are interesting and by definition will result in a very very small number of WPUs so that the system can check when to delete your document. I was curious whether the Good code snippet you posted actually works - one reason you could be seeing this behavior is because the change never actually creates TTL index. Please let me know?

2 Likes

In my case I have the same or very similar problem, but in my case I am using Prisma ORM, I have tried to apply a solution similar to yours, but I have not been successful.

For the case of applications that use Prisma ORM, do you know where the problem could be and how I could solve it?

Thanks!