title: mongo shell cat() file to big to load as a variable at
body: <p>I have javascript that I load to mongo to get some info. </p>
  
  <pre><code>mongo --port=27017 script.js
  </code></pre>
  
  <p>I am passing ObjectIds from the file as a variable:</p>
  
  <pre><code>#script.js
  
  db=connect('127.0.0.1:27017/dbname')
  db.auth('user', 'pass') //get credentials
  
  
  var file = cat('file_with_ids.txt');  // read the file
  var objectId = file.split('\n');
  for (var k =0, j = objectId.length-1; k&lt;j; k++){
      someFunction(objectId[k])
  
  }
  </code></pre>
  
  <p>It works with files with (500K rows), but I have files with 1.5 M and more records that I need to work on. 
  I was not successful finding documentation on mongodb cat() and its internals.
  I know that I can split the file into chunks and feed one by one using <strong>bash script</strong>, but I do not want to go that route. 
  Limitations:
  <strong>I can only use pure JS</strong>, no node (could have been easier).  I have written python code to do it, it works but python (pymonogo) reorders the order of the documents. </p>
  
  <p>Any suggestions? How to solve this in pure JS? Thanks</p>