Skip to content

Latest commit

 

History

History
52 lines (43 loc) · 1.06 KB

File metadata and controls

52 lines (43 loc) · 1.06 KB

Mongo

GoDoc

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.

License

Mongo is licensed under the MIT license.

Installation

To install mongo, simply run go get github.com/sfreiberg/mongo.

Example

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)
	}
}