title: MongoDB - distinct and count, the simplest case
body: <p>I have database XXX and collection YYY in MongoDB (using MongoLab). </p>
  
  <p>Here is a sample record:</p>
  
  <pre><code>{
   "_id": {
      "$oid": "551a5asdfsdfsdfs"
   },
   "_class": "com.test.com",
   "mvid": "d0fffsdfs"
  
  }
  </code></pre>
  
  <p>I would like to retrieve all distinct values of the field "mvid" and count them. 
  Here is what found on the internet:</p>
  
  <pre><code>db.YYY.aggregate([{ $group: { _id: "$mvid"}  },{ $group: { _id: 1, count: { $sum: 1 } } }])
  </code></pre>
  
  <p>I also tried </p>
  
  <pre><code>XXX.YYY.aggregate([{ $group: { _id: "$mvid"}  },{ $group: { _id: 1, count: { $sum: 1 } } }])
  </code></pre>
  
  <p>I put the above into command text box, in both cases I get the following error message: "We encountered an error while parsing your JSON. Please check your syntax (e.g. ensure you are using double quotes around both your field names and values) and try again."</p>
  
  <p>What am I doing wrong?</p>