Debugging Strategies

34 views
Skip to first unread message

sc28

unread,
May 26, 2015, 3:38:38 PM5/26/15
to mgo-...@googlegroups.com
I have a relatively complex structure that when I execute the mgo query, nothing (but defaults) fill my struct.

For example:

type MyStruct {
    Verified          string `json:"DigitalSignature"`
    Immutable     ImmutableValues `json:"Immutable"`
    Mutable         Mutable 'json:"Mutable"`  
}

// values that cannot be changed
type Immutable struct {
   Organization        string `json:"Organization" bson:"Organization"`
   ...
}

type Mutable struct {
    Settings      AppSettings
    OtherStuff  OtherStuff
}

type Settings struct {
    EnableUpdates              bool   `json:"EnableUpdates" bson:"EnableUpdates"`
    ...
}


When I issue a mongo select statement (i.e.,  "Organization":"xyz") I can see the record is returned, but populating a struct only gives the default values, e.g.

...
var orgData MyStruct
err := mongoSession.DB("myDB").C("collection").Find(bson.M{"Organization":"xyz"}).One(&orgData)
... convert to json (MarshalIndent()..)
fmt.Println(string(bytes))  <-- only see the default struct values

To verify that I;m finding the record, I changed this:
var orgData interface{}
...
Now printing shows all the correct record values.

So obviously there is a mapping issue going on between my struct definitions and what is being returned - what is the best way to determine what s happening under the hood (a debugger here would be nice :-)  )









Gustavo Niemeyer

unread,
Jun 4, 2015, 10:32:35 AM6/4/15
to mgo-...@googlegroups.com

The debugging log in mgo is very comprehensive. You can enable it by doing:

    mgo.SetLogger(logger)
    mgo.SetDebug(true)

That logger value is obtained from the standard log package (log.New).

If you have a snippet that demonstrates your issue, I'm happy to look at it as well. Just make it self-contained please (should create the necessary data by itself).


--
You received this message because you are subscribed to the Google Groups "mgo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mgo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages