I'm just guessing but in case you just want to retrieve all Transaction documents and print them - here is how:
Given you have a struct
representing the structure of the documents of your collection e.g.:
type Transaction struct {
Id bson.ObjectId `bson:"_id"`
TransactionId string `bson:"transId"`
}
You can obtain all the documents using the MongoDB driver (mgo):
var transactions []Transaction
err = c.Find(bson.M{}).All(&transactions)
// handle err
for index, transaction := range transactions {
fmt.Printf("%d: %+v\n", index, transaction)
}
Addition (generic solution)
OK, after you provided some more insight this might be a generic solution without using a struct. Try to marshall into a BSON document bson.M
(not tested):
var data []bson.M
err := c.Find(bson.M{}).All(&data)
// handle err
for _, doc := range data {
for key, value := range doc {
fmt.Println(key, value)
}
}