I am using this tutorial/app template to play around with rails3 and mongoid and the generated datatype for user_id clearly isn’t integer as the first user has this id: 4defd4b5ab104d5ea1000001.
What is the datatype used by Devise or the tutorial and for future reference where did you find it defined in the app template/devise?
The type is called “ObjectId” and is a native BSON type. BSON is a binary JSON-like data format used internally by mongo.
See, http://bsonspec.org/#/specification for the BSON specs and http://www.mongodb.org/display/DOCS/Object+IDs for a discussion on this type.
ObjectIds are the default unique identifier of mongo documents (the “_id” field) and are usually client generated (upserts being the exception). They are (practically) collision safe as they have a time, process id, machine id and a random/increment component.