Skip to content

rs/rest-layer-mongo

Repository files navigation

REST Layer MongoDB Backend

godoc license build

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.

About

REST Layer MongoDB resource storage handler

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages