4

Can someone explain how RPUs are getting calculated by an example ?

Let's say I have a mongo collection that has 5 million documents. So if i do a findOne to the collection, the RPUs generated would be 5M or 1 ?

droid
  • 53
  • 3

1 Answers1

10

It depends on a crucially import step that I could not find anywhere in Mongo's pricing information.

I had 4000 daily visits with a user database of 25,000 users. I was using findOne on the database two times per page load. What I thought would be 8000 RPUs turned out to be 170 million RPUs. That's right - 42,500 RPUs per page visit.

So the critically important step is: add indexes for the keys you're matching on.

Yes this is an obvious step to optimize performance, but also easy to overlook the first go-around of creating a database.

I was in the MongoDD dashboard daily to check user stats and was never alerted to any abnormalities. Searching online for over an hour, I could not find any mention of this from Mongo. But when I reached out to support, this is the first thing they pointed out. So they know it's an issue. They know it's a gotcha. They know how simple it'd be to point out that a single call is resulting in 40,000 RPUs. Doesn't seem that they care. Rather it seems to be a sleezy business model they've intentionally adopted.

So if you do a findOne on a 5 million document database, will you get 1 RPU charged or 5 Million RPUs charged? Depends if you remembered to index.

komcdo
  • 116
  • 1
  • 2
  • So if you had no index, and every document was 4kb, a findOne WOULD result in 5M RPUs used? – J. Doe Oct 03 '22 at 08:33
  • If you do index the 5 million documents on the findOne query. Is it only 1RPU for a findOne? – jacktim Feb 20 '23 at 00:58
  • Yes J.Doe. You would also get charged the same even if each document was 0.25kb. Yes @jacktim. 5 million X pricing if OP forgets to index. I learned the hard way (luckily with only 20,000x pricing). – komcdo Feb 21 '23 at 06:25
  • _id is automatically indexed. But if you're trying to findOne on a field other than _id that is not indexed (for example "name" or "email"), then it will "read" every single item in your database until it finds a match. – komcdo Mar 07 '23 at 20:10