title: How can I use mongodb projections with Go and mgo?
body: <p>I am currently trying to extract a single object within a document array inside of mongodb. 
  This is a sample dataset:</p>
  
  <pre><code>"_id" : ObjectId("564aae61e0c4e5dddb07343b"),
  "name" : "The Races",
  "description" : "Horse races",
  "capacity" : 0,
  "open" : true,
  "type" : 0,
  "races" : [
      {
          "_id" : ObjectId("564ab9097628ba2c6ec54423"),
          "race" : {
              "distance" : 3000,
              "user" : {
                  "_id" : ObjectId("5648bdbe7628ba189e011b18"),
                  "status" : 1,
                  "lastName" : "Miranda",
                  "firstName" : "Aramys"
              }
          }
      },
      {
          "_id" : ObjectId("564ab9847628ba2c81f2f34a"),
          "bet" : {
              "distance" : 3000,
              "user" : {
                  "_id" : ObjectId("5648bdbe7628ba189e011b18"),
                  "status" : 1,
                  "lastName" : "Miranda",
                  "firstName" : "Aramys"
              }
          }
      },{...}
  ]
  </code></pre>
  
  <p>I can successfully query using the following in mongo:</p>
  
  <pre><code>db.tracks.find({"_id": ObjectId("564aae61e0c4e5dddb07343b")}, {"races": { $elemMatch: {"_id": ObjectId("564ab9847628ba2c81f2f34a")}}}).pretty()
  </code></pre>
  
  <p>I am unable to do the same using mgo and have tried the following:</p>
  
  <p>Using nesting (Throws: missing type in composite literal, missing key in map literal)</p>
  
  <pre><code>// Using nesting (Throws: missing type in composite literal, missing key in map literal)
  c.Find(bson.M{{"_id": bson.ObjectIdHex(p.ByName("id"))}, bson.M{"races": bson.M{"$elemMatch": bson.M{"_id": bson.ObjectIdHex(p.ByName("raceId"))}}}}).One(&amp;result)
  
  // Using select (Returns empty)
  c.Find(bson.M{"_id": bson.ObjectIdHex(p.ByName("id"))}).Select(bson.M{"races._id": bson.ObjectIdHex(p.ByName("raceId"))}).One(&amp;result)
  
  //As an array (Returns empty)
  c.Find([]bson.M{{"_id": bson.ObjectIdHex(p.ByName("id"))}, bson.M{"races": bson.M{"$elemMatch": bson.M{"_id": bson.ObjectIdHex(p.ByName("raceId"))}}}}).One(&amp;result)
  </code></pre>
  
  <p>I am using httprouter and p.ByName("...") invocations are parameters passed to the handler.</p>
  
  <p>Thanks in advance.</p>