Created
March 18, 2015 23:44
-
-
Save lettergram/3032034543eab21345bd 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
// 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