When making massive inserts it reaches a point where the server rejects new inserts with the following error in the logs:
ERROR: mmap() failed for ...
len: .... errno:12 Cannot allocate memory
We have tested making it in PHP and Python, and the problem is the same in both.
The attachment is a simple script in PHP which causes the error
We have apparently solver it telling the kernel not to limit the memory size of the MongoDB project with the command
sysctl -v unlimited