天天看点

Golang之使用mgo连接MongoDB

session, err := mgo.Dial("localhost:27017") 
if err != nil { 
     log.Println("err: ", err) 
     return 
} 
defer session.Close() 
// Optional. Switch the session to a monotonic behavior. 
session.SetMode(mgo.Monotonic, true) 
c := session.DB("logs").C("log_event")