Created
August 7, 2018 05:51
-
-
Save novalagung/33576ada99836d665c2eda5baf8b1462 to your computer and use it in GitHub Desktop.
This file contains 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
// Get session | |
info := new(mgo.DialInfo) | |
info.Username = "username" | |
info.Password = "password" | |
info.Source = "admin" | |
info.Addrs = []string{"host"} | |
info.Database = "dbname" | |
session, err := mgo.DialWithInfo(info) | |
if err != nil { | |
fmt.Printf("dial fail %v\n", err) | |
os.Exit(1) | |
} | |
defer session.Close() | |
// Error check on every access | |
session.SetSafe(&mgo.Safe{}) | |
// Get collection | |
collection := session.DB("dbname").C("collectionName") | |
// Delete record | |
err = collection.Remove(bson.M{}) | |
if err != nil { | |
fmt.Printf("remove fail %v\n", err) | |
os.Exit(1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment