How to generate unique identifiers for use with MongoDB

This blog article has been re-published with my permission by MongoDB at https://www.mongodb.com/blog/post/generating-globally-unique-identifiers-for-use-with-mongodb Motivation By default, MongoDB generates a unique ObjectID identifier that is assigned to the _id field in a new document before writing that document to the database. In many cases the default unique identifiers assigned by MongoDB will meet application requirements. However, in some cases an application may need to create custom unique identifiers, such as: The application may require unique identifiers with a precise number of digits. For example, unique 12 digit identifiers might be required for bank account numbers. Unique identifiers may need to be generated in a monotonically increasing and continuous sequential order. Unique identifiers may need to be independent of a specific database vendor. Due to the multi-threaded and distributed nature of modern applications, it is not always a straightforward task to generate unique identifiers that satisfy application requirements. ...

January 30, 2017