title: How can we count the number of items in arraylist from different documents in mongodb java?
body: <p>Assuming I have these documents:</p>
  
  <pre><code>{ "_id" : 1, "item" : "ABC1", "description" : "product 1", colors: [ "blue", "black", "red" ] }
  { "_id" : 2, "item" : "ABC2", "description" : "product 2", colors: [ "blue", "purple" ] }
  { "_id" : 3, "item" : "XYZ1", "description" : "product 3", colors: [ "red", "yellow"] }
  </code></pre>
  
  <p>The result I would like is </p>
  
  <pre><code>blue : 2 
  red : 2
  black : 1
  purple : 1
  yellow : 1 
  </code></pre>
  
  <p>Is this possible to perform using the mongodb or do I need to manually implemented after getting colors array in Java? Hints or any help would be of very useful.</p>
  
  <p>This is how I get the database and the collections</p>
  
  <pre><code>MongoClient mongoClient = new MongoClient("localhost", 27017);
  MongoCollection&lt;Document&gt; collection = mongoClient.getDatabase("tweets")
              .getCollection("tweet");
  </code></pre>