Accessing another collection in MongoDB map decreases
If you try this locally, it will work. However, this fails entirely in the case of a folded scenario, because the collection or data in the collection will not be local to the shard.
This is also bad practice because M / R can cause cascading requests that are difficult to track down.
If you encounter this problem, you have several options:
- Denormalize data . If
from the collection
, copy those fields to
. Yes it is not normalized, but MongoDB is not a relational database, it is not meant to be normalized.
- Multicomponent M / R . In many cases, you can achieve the same result by performing several different operations and writing the results to a single collection. Perhaps you do the M / R on first
and then loop through the output and update the data from
in a separate script / process.
I've seen both. I've even seen # 2 converted to a simple loop
that processes both parts at the same time. I have successfully replaced some M / R jobs with simple loops
source to share