Last active
September 19, 2017 08:54
-
-
Save hfogelberg/cc44a2e53d133de585b77dc3aed4ae15 to your computer and use it in GitHub Desktop.
Create Mongo connection from Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "gopkg.in/mgo.v2" | |
type Connection struct { | |
DB *mgo.Database | |
} | |
const MongoDb = "test" | |
func main() { | |
host := os.Getenv("MONGO_DB_HOST") | |
session, err := mgo.Dial(host | |
if err != nil { | |
log.Printf("Cannot connect to Db %s\n", err.Error()) | |
return | |
} | |
defer session.Close() | |
session.SetMode(mgo.Monotonic, true) | |
connection := Connection{session.DB(MognoDb)} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment