Skip to content

sfreiberg/mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Simple CRUD operations for mongo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages