The following example shows how to delete a document using the name"Foo Bar" from the collection of peoplethe database teston localhostit uses of the API: Remove()
session, err := mgo.Dial("localhost")
if err != nil {
fmt.Printf("dial fail %v\n", err)
os.Exit(1)
}
defer session.Close()
session.SetSafe(&mgo.Safe{})
collection := session.DB("test").C("people")
err = collection.Remove(bson.M{"name": "Foo Bar"})
if err != nil {
fmt.Printf("remove fail %v\n", err)
os.Exit(1)
}
source
share