title: MongoDB - How to access an object in an array
body: <p>I'm not able to describe my thought precisely in words, so here's an example:</p>
  
  <pre><code>[
    {
      'description': 'fruits',
      'examples': [
        {
          'name': 'Apple',
          'color': ['red', 'green']
        },
        {
          'name': 'Banana',
          'color': 'yellow'
        }
      ]
    },
    {
      'description': 'vegetables',
      'examples': [
        {
          'name': 'Tomato',
          'color': 'red'
        },
        {
          'name': 'Carrot',
          'color': 'orange'
        }
      ]
    },
    {
      'description': 'Wweets',
      'examples': [
        {
          'name': 'Chocolate',
          'color': ['brown', 'black', 'white']
        },
        {
          'name': 'Candy',
          'color': 'various'
        }
      ]
    }
  ]
  </code></pre>
  
  <p>Let's go step by step:</p>
  
  <p>If I want to see all food categories, I query by the following command</p>
  
  <pre><code>db.food.find()
  </code></pre>
  
  <p>I want to see the vegetables</p>
  
  <pre><code>db.food.find({ 'description': 'vegetables' })
  </code></pre>
  
  <p><strong>Now let's say I forgot how a Carrot looks like (lol). What do I do?</strong> I tried the following (Native node.js MongoDB driver):</p>
  
  <pre><code>collection.find({'examples.name': 'Carrot'}, function(err, example){
    console.log(example)
    // It still returns me the whole object!
  });
  </code></pre>
  
  <p>As a result I expected MongoDB to return the next highest instance of the object. For example I wanted to do this.</p>
  
  <pre><code>console.log(example.color)
  // 'orange'
  </code></pre>
  
  <p>Do you have any idea? I'm new to document oriented DBs :/</p>