Unique IDs with mongodb

As long as you can guarantee uniqueness, you’re not constrained to using the default “_id” MongoDB supplies.

Therefore, it’s down to you how you generate this number. If you’d like to store this number inside MongoDB, then you could store it in a separate collection and increment it for every new URL required.

Incrementing a field is achieved by using the $inc verb, or you may want to take a look at how MongoDB can atomically update or increment a value.

Leave a Comment