0

I'm trying to understand how to collect data from mongodb using Go. I created a sample database and filled it with one "person" with id, login, and password data fields. Here's my struct

type Person struct {
id     bson.ObjectId   `json:"id" bson:"_id"`
login  string          `json:"login" bson:"login"`
pass   string          `json:"pass" bson:"pass"`}

On the mgo documentation, the &data object says to be a interface{} type. I have it defined as a Person struct, yet it still compiles.

data := Person{}
c.Find(bson.M{"login": "Larry"}).One(&data)
fmt.Printf("(%v)\n", data.pass)

When I run the code, it prints: ()

Not sure what I'm doing wrong. If it should be an interface{} type, how could I format that Person interface?

  • 1
    Quoting comment on accepted answer in thread linked by @CeriseLimón: "Identifiers that start with capital letter are exported, it means they are accessible from all packages." You are obviously missing the same point. – Thomas Urban Nov 29 '17 at 23:38
  • Very much a duplicate, thank you for showing me to that! – D.Ritchie Nov 30 '17 at 00:43

0 Answers0