Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created March 18, 2015 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lettergram/3032034543eab21345bd to your computer and use it in GitHub Desktop.
Save lettergram/3032034543eab21345bd to your computer and use it in GitHub Desktop.
// Finds book already in database
func FindBook(bookid string) (book *Book) {
session, err := mgo.Dial("127.0.0.1:27017/")
if err != nil {
fmt.Println(err)
return nil
}
// Opens the "library" databases, "books" collection
c := session.DB("library").C("books")
// Finds the bookid and fills the book struct with the data
err = c.Find(bson.M{"id": bookid}).One(&book)
// close session to free resources
session.Close()
return book
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment