I am trying to read some data from MongoDB in go using gopkg.in/mgo.v2 driver. i have written the following code to extract the information form MongoDB.
my go struct
type NetworkUser struct {
Id bson.ObjectId `bson:"_id,omitempty" json:"-"`
FirstName string `bson:"firstName" json:"firstName"`
MiddleName string `bson:"middleName,omitempty" json:"middleName,omitempty"`
LastName string `bson:"lastName" json:"lastName"`
Inserted time.Time `bson:"inserted" json:"-"`
}
then, i have written the following code for reading from the mongo
//Connect to the Collection and Execute query
_collection := _session.DB(database).C(collection)
//Executing the query
var results []NetworkUser
err = _collection.Find(query).All(&results)
//Handle the errors
if err != nil {
fmt.Println(err)
panic(err)
}
When i run the code, i am getting the following error : Can't marshal string as a BSON document
Please let me know, if anyone come across this error and how to fix it..