The mongo package is a very simple wrapper around the github.com/globalsign/mgo package. It's purpose is to allow you to do CRUD operations with very little code. It's not exhaustive and not meant to do everything for you.
Mongo is licensed under the MIT license.
To install mongo, simply run go get github.com/sfreiberg/mongo
.
package main
import (
"github.com/sfreiberg/mongo"
"github.com/globalsign/mgo/bson"
)
type Customer struct {
Id bson.ObjectId `bson:"_id"`
Firstname string
Lastname string
}
func init() {
// Set server (localhost) and database (MyApp)
err := mongo.SetServers("localhost", "MyApp")
if err != nil {
panic(err)
}
}
func main() {
customers := []interface{}{
&Customer{
Firstname: "George",
Lastname: "Jetson",
},
&Customer{
Firstname: "Judy",
Lastname: "Jetson",
},
}
err := mongo.Insert(customers...)
if err != nil {
panic(err)
}
}