title: Should I use the "allowDiskUse" option in a product environment?
body: <p>Should I use the allowDiskUse option when returned doc exceed 16MB limit in aggregation? </p>
  
  <p>Or should I alter db structure or codes logic to avoid the limit? 
  What's the advantage and disadvantage of 'allowDiskUse'? 
  Thanks for your help.</p>
  
  <p>Hers is the official doc I have seen:
  Result Size Restrictions</p>
  
  <p>Changed in version 2.6.</p>
  
  <p>Starting in MongoDB 2.6, the aggregate command can return a cursor or store the results in a collection. When returning a cursor or storing the results in a collection, each document in the result set is subject to the BSON Document Size limit, currently 16 megabytes; if any single document that exceeds the BSON Document Size limit, the command will produce an error. The limit only applies to the returned documents; during the pipeline processing, the documents may exceed this size.</p>
  
  <p>Memory Restrictions¶</p>
  
  <p>Changed in version 2.6.</p>
  
  <p>Pipeline stages have a limit of 100 megabytes of RAM. If a stage exceeds this limit, MongoDB will produce an error. To allow for the handling of large datasets, use the allowDiskUse option to enable aggregation pipeline stages to write data to temporary files.
  <a href="https://docs.mongodb.com/manual/core/aggregation-pipeline-limits/" rel="noreferrer">https://docs.mongodb.com/manual/core/aggregation-pipeline-limits/</a></p>