How many RPUs does it take in MongoDB aggregation, if multiple documents in the collection loopup to a single document in another collection?
I have a serverless instance in MongoDB Atlas.
I have two collections: Organizations and Users.
Every User is part of one Organization i.e. organizationId is stored in every user document.
Let’s say right now I have only one document in the Organization collection. How many RPUs does it take for the below aggregate?
db.users.aggregate([
{
$lookup: {
from: 'organizations',
localField: 'organizationId',
foreignField: '_id',
as: 'organization',
},
},
{
$unwind: {
path: '$organization',
preserveNullAndEmptyArrays: true,
}
}
]);
The result of the above query is a list of 100 users.
If each document scan is 1 RPU under 4kb, if there is only a single document in the organization collection and all 100 users are part of it.
1.) If each user lookup is considered.
total RPUs = 100 RPUs (100 user documents) + 100 RPUs(for each lookup in organization) = 200 RPUs
2.) Since there is only one organization.
total RPUs = 100 RPUs (100 user documents) + 1 RPUs = 101 RPUs
Which one is the correct value, is it 200 or 101 RPU?