title: Mongorestore seems to run out of memory and kills the mongo process
body: <p>In current setup there are two Mongo Docker containers, running on hosts A and B, with Mongo version of 3.4 and running in a replica set. I would like to upgrade them to 3.6 and increase a member so the containers would run on hosts A, B and C. Containers have 8GB memory limit and no swap allocated (currently), and are administrated in <a href="https://en.wikipedia.org/wiki/Rancher_Labs" rel="noreferrer">Rancher</a>. So my plan was to boot up the three new containers, initialize a replica set for those, take a dump from the 3.4 container, and restore it the the new replica set master. </p>
  
  <p>Taking the dump went fine, and its size was about 16GB. When I tried to restore it to the new 3.6 master, restoring starts fine, but after it has restored roughly 5GB of the data, mongo process seems to be killed by OS/Rancher, and while the container itself doesn't restart, MongoDB process just crashes and reloads itself back up again. If I run mongorestore to the same database again, it says unique key error for all the already inserted entries and then continue where it left off, only to do the same again after 5GB or so. So it seems that mongorestore loads all the entries it restores to memory.</p>
  
  <p>So I've got to get some solution to this, and:</p>
  
  <ol>
  <li>Every time it crashes, just run the mongorestore command so it continues where it left off. It probably should work, but I feel a bit uneasy doing it.</li>
  <li>Restore the database one collection at a time, but the largest collection is bigger than 5GB so it wouldn't work properly either.</li>
  <li>Add swap or physical memory (temporarily) to the container so the process doesn't get killed after the process runs out of physical memory.</li>
  <li>Something else, hopefully a better solution?</li>
  </ol>