Go and MongoDB Initial Test

This was so easy. Going against the database that runs this site:

package main

import ( 
    "fmt"
    "gopkg.in/mgo.v2"
    "gopkg.in/mgo.v2/bson"
)


type Post struct {
    Body string
    Title string    `bson:"title"`
    Tags []string
}

func main() {
    session, _ := mgo.Dial("localhost")
    defer session.Close()

    db := session.DB("jtccom")

    posts := db.C("posts")

    var first Post
    posts.Find(bson.M{}).One(&first)

    fmt.Println(first.Title)

}

Here we go.

blog comments powered by Disqus