Skip to content
REST Layer MongoDB resource storage handler
Branch: master
Clone or download
Pull request Compare This branch is 3 commits ahead, 1 commit behind rs:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

REST Layer MongoDB Backend

godoc license build

This REST Layer resource storage backend stores data in a MongoDB cluster using mgo.


import ""

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.

You can’t perform that action at this time.