A quick hint, on how to have an 'id' attribute in Mongoid document JSON:
When you serialize Mongoid objects to JSON, you won't get ID attribute, similar to ActiveRecord. Instead you'll have "_id" attribute containing "$oid" value:
{ "_id": {"$oid":"52d3fdfd53656e5180020000"}, "changed_at":"2014-02-15", "created_at":"2014-01-13T15:53:49.444+01:00", "updated_at":"2014-01-13T15:53:49.444+01:00" }
If you would prefer something like this:
{ "id": "52d3fdfd53656e5180020000", "_id": {"$oid":"52d3fdfd53656e5180020000"}, "changed_at":"2014-02-15", "created_at":"2014-01-13T15:53:49.444+01:00", "updated_at":"2014-01-13T15:53:49.444+01:00" }
Just put this into your initializers (for example in config/initializers/mongoid.rb):
module Mongoid module Document def as_json(options={}) attrs = super(options) attrs["id"] = attrs["_id"].to_s attrs end end end