title: Read data from type []primitive.M Go
body: <p>I write code to read data from MongoDB.</p>
  
  <p>And the output type is <code>[]primitive.M</code></p>
  
  <p>Here is my code</p>
  
  <pre><code>func GetAllChildOfNode(node string) error {
      ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
      client, err := mongo.Connect(ctx, options.Client().ApplyURI("URI"))
      if err != nil {
          return err
      }
      defer client.Disconnect(ctx)
      database := client.Database("users")
      users := database.Collection("users")
      matchStage := bson.D{{"$match", bson.D{{"username", node}}}}
      graphStage := bson.D{{"$graphLookup", bson.D{{"from", "users"}, {"startWith", "$username"}, {"connectFromField", "userparentid"}, {"connectToField", "userparentid"}, {"as", "descendants"}}}}
      unWind := bson.D{{"$unwind", "$descendants"}}
      replaceRoot := bson.D{{"$replaceRoot", bson.D{{"newRoot", "$descendants"}}}}
      proJect := bson.D{{"$project", bson.D{{"descendants", 0}}}}
      showInfoCursor, err := users.Aggregate(ctx, mongo.Pipeline{matchStage, graphStage, unWind, replaceRoot, proJect})
      if err != nil {
          panic(err)
      }
      var showsWithInfo []bson.M
      if err = showInfoCursor.All(ctx, &amp;showsWithInfo); err != nil {
          panic(err)
      }
      fmt.Println(showsWithInfo)
      fmt.Println("---------------------")
      fmt.Printf("%T \n", showsWithInfo)
      fmt.Println("---------------------")
      return nil
  }
  </code></pre>
  
  <p>And here is my output result:</p>
  
  <pre><code>[map[_id:ObjectID("5ebd05b52f37000085002219") comdepartment:BOMON_VIENTHONG comid:DHBK lastname:SV1_BMVT password:123456 usercode:DHBK_0015 userdate:2020-05-05 useremail:SV1_BMVT@edu.com.vn username:SV1_BMVT userparentid:GV_BMVT userstatus:ACTIVE usertel:0907111015 usertype:USER_COM] map[_id:ObjectID("5ebd05b52f3700008500221a") comdepartment:BOMON_VIENTHONG comid:DHBK lastname:SV2_BMVT password:123456 usercode:DHBK_0016 userdate:2020-05-05 useremail:SV2_BMVT@edu.com.vn username:SV2_BMVT userparentid:GV_BMVT userstatus:ACTIVE usertel:0907111016 usertype:USER_COM]  map[_id:ObjectID("5ece3517b8d5570916d013f6") comdepartment:BOMON_VIENTHONG comid:DHBK lastname:SV5_BMVT password:123 usercode:DHBK_0019 userdate:2020-05-14 useremail:SV5_BMVT@edu.com.vn username:SV5_BMVT userparentid:GV_BMVT userstatus:ACTIVE usertel:0907111019 usertype:USER_COM]  map[_id:ObjectID("5ebd05b52f3700008500221b") comdepartment:BOMON_VIENTHONG comid:DHBK lastname:SV3_BMVT password:123456 usercode:DHBK_0017 userdate:2020-05-05 useremail:SV3_BMVT@edu.com.vn username:SV3_BMVT userparentid:GV_BMVT userstatus:ACTIVE usertel:0907111017 usertype:USER_COM] 
    map[_id:ObjectID("5ebd05b52f3700008500221c") comdepartment:BOMON_VIENTHONG comid:DHBK lastname:SV4_BMVT password:123456 usercode:DHBK_0018 userdate:2020-05-05 useremail:SV4_BMVT@edu.com.vn username:SV4_BMVT userparentid:GV_BMVT userstatus:ACTIVE usertel:0907111018 usertype:USER_COM]  map[_id:ObjectID("5eddf0a9b8d5570916dae6ff") comdepartment:BOMON_VIENTHONG comid:DHBK lastname:SV6_BMVT password:123456 usercode:DHBK_0019 userdate:2020-06-08 useremail:SV6_BMVT@edu.com.vn username:SV6_BMVT userparentid:GV_BMVT userstatus:ACTIVE usertel:0907111020 usertype:USER_COM]]
  ---------------------
  []primitive.M 
  ---------------------
  </code></pre>
  
  <p>But I don't now how to get <code>username</code> only from <code>[]primitive.M</code> type. For example</p>
  
  <p><code>TRUONGKHOA_BMVT,PHOKHOA_BMVT,THUKY_BMVT,GV_BMVT,SV1_BMVT,SV2_BMVT,SV3_BMVT,SV4_BMVT,SV5_BMVT,SV6_BMVT</code></p>