# README
REST Layer MongoDB Backend
This REST Layer resource storage backend stores data in a MongoDB cluster using mgo.
Usage
import "github.com/rs/rest-layer-mongo"
Create a mgo master session:
session, err := mgo.Dial(url)
Create a resource storage handler with a given DB/collection:
s := mongo.NewHandler(session, "the_db", "the_collection")
Use this handler with a resource:
index.Bind("foo", foo, s, resource.DefaultConf)
You may want to create a many mongo handlers as you have resources as long as you want each resources in a different collection. You can share the same mgo
session across all you handlers.
Object ID
This package also provides a REST Layer schema.Validator for MongoDB ObjectIDs. This validator ensures proper binary serialization of the Object ID in the database for space efficiency.
You may reference this validator using mongo.ObjectID as schema.Field.
A mongo.NewObjectID
field hook and mongo.ObjectIDField
helper are also provided.
# Functions
NewHandler creates an new mongo handler.
# Variables
NewObjectID is a field hook handler that generates a new Mongo ObjectID hex if value is nil to be used in schema with OnInit.
ObjectIDField is a common schema field configuration that generate an Object ID for new item id.
# Type aliases
Handler handles resource storage in a MongoDB collection.