I’m doing a POC (proof of concept) sample program to connect to my mongo database - ‘test’ and now I want to be able to display the collections and documents from Go.
Here’s my code so far.
package main
import (
"fmt"
"gopkg.in/mgo.v2"
)
type DocumentData struct {
Name string `bson:"name"`
Class string `bson:"class"`
}
func main() {
// Connection
session, err := mgo.Dial("localhost:27017")
if err != nil {
fmt.Printf("Can't connect", err)
}
defer session.Close()
c := session.DB("test").C("testCollections") // My mongo DB is called 'test' and collection: 'testCollections'
// Find data
}
}