title: MongoDB find a given field and get average value
body: <p>I'd like to get the average in a collection for a given property value. What am I doing wrong?   </p>
  
  <pre><code>[{name:'Bob',city:'Barcelona',trips: 1 },
  {name:'Bruce',city:'Barcelona',trips: 5 },
  {name:'Bruno',city:'València',trips: 2 },
  {name:'Bart',city:'Barcelona',trips: 3 }]
  
  db.x.aggregate([{$group:{city:'Barcelona', $avg:"$trips"}}]);
  </code></pre>