title: MongoDB Query to find out all the array elements of a collection
body: <p>I have a pretty big MongoDB document that holds all kinds of data. I need to identify the fields that are of type array in a collection so I can remove them from the displayed fields in the grid that I will populate.</p>
  
  <p>My method now consists of retrieving all the field names in the collection with</p>
  
  <p><em>This was taken from the response posted here <a href="https://stackoverflow.com/questions/2298870/mongodb-get-names-of-all-keys-in-collection">MongoDB Get names of all keys in collection</a></em></p>
  
  <pre><code>mr = db.runCommand({
    "mapreduce" : "Product",
    "map" : function() {
      for (var key in this) { emit(key, null); }
    },
    "reduce" : function(key, stuff) { return null; }, 
    "out": "things" + "_keys"
  })
  
  db[mr.result].distinct("_id")
  </code></pre>
  
  <p>And running for each of the fields a query like this one</p>
  
  <pre><code>db.Product.find( { $where : "Array.isArray(this.Orders)" } ).count()
  </code></pre>
  
  <p>If there's anything retrieved the field is considered an array.</p>
  
  <p>I don't like that I need to run n+2 queries ( n being the number of different fields in my collection ) and I wouldn't like to hardcode the fields in the model. It would defeat the whole purpose of using MongoDB.</p>
  
  <p>Is there a better method of doing this ?</p>