mongoid - Creating short, unique object id's in MongoDB -


i'm making app similar instagram using rails/mongoid. want unique id can use in url http://instagr.am/p/djmu8/

what's easiest way that? can derive such id default bson objectid mongo creates?

you may try use first 4 bytes of objectid (they represent timestamp).

but, 100% safe, it's better produce unique short id, implementing counter. can use separate collection maintain current value of counter.

more details on mongo's objectid structure can found here: http://www.mongodb.org/display/docs/object+ids

as alternative can convert convert hex string id representation representation based on 36 symbols (26 latin letters + 10 digits). shorter.

it seems, there ruby library, can such conversions http://rubyworks.github.com/radix/


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -