I am working with mgo
to use MongoDB with Go. I have the following code:
func Find(collectionName, dbName string, query interface{}) (result []interface{}, err error) {
collection := session.DB(dbName).C(collectionName)
err = collection.Find(query).All(&result)
return result, err
}
func GetTransactionID() (id interface{}, err error) {
query := bson.M{}
transId, err := Find("transactionId", dbName, query)
for key, value := range transId {
fmt.Println("k:", key, "v:", value)
}
}
Output:
k: 0 v: map[_id:ObjectIdHex("536887c199b6d0510964c35b") transId:A000000000]
I need to get the values of _id
and transId
from the map value returned in the slice from Find
. How can I do that?