So I'm used to looking up submissions by an auto increment primary ID with MySQL, but after using the MongoDB ORM wrapper, Mongoose, I'm finding that since Mongo stores data within collections differently, there is not really any concept of a traditional auto-increment ID.

I'm stuck trying to figure out how to grab a submission now because normally I'd structure my URL like so:

submission/34/category/slug-goes-here.

Since the 34 now becomes an ugly string based UUID with Mongo, I don't necessary want to display that in my URLs, but I want a unique URL in order to look up my submissions.

I'm thinking of maybe having a set method that when I insert the submission into my database, it generates some kind of 6 character hash e.g. zhXk40 and looks it up like that.

I'm wondering if I do it like this what the performance trade-offs would be. If I made constraints on the slug and then looked them up with the slug, and verified that the category matched, would that be more efficient? Either way I'm going to have to check if the category and slug match, but I'm not sure if an ID is even really necessary in this case.

What's the best practice for creating a route + looking up some piece of data from the db based on that route?

Great answer. Good to know that I have this option, but thinking about it more seems to be much more of a pain that I'm interested in. Eventually if I want to take advantage of sharding, it seems like it'll become a pain since I won't know which cluster would have its id incremented. I'll go with just looking it up with its object ID for now. Thanks :)
–
bob_cobbMar 5 '13 at 17:35