Re: Auto-increment ids

121 views
Skip to first unread message

Kevin English

unread,
Aug 31, 2012, 7:02:13 PM8/31/12
to mongod...@googlegroups.com
Base 64 is a little better:
http://sebastian.formzoo.com/2012/04/12/mongodb-shorten-the-objectid/ 

On Friday, August 31, 2012 5:48:28 PM UTC-5, Mase wrote:
I understand that auto-incrementing Ids in MongoDB are not a great idea for multiple reasons. I've been reading up on this in multiple places, but I still have some need for it.

Mainly it's about URLs for me. I don't generally have an issue with ObjectId's, but when they end up in the URL of a web app, they're very ugly and bad for SEO. It would be better if I could have a much smaller ID to place in the URL. These auto-incrementing IDs in my case would not be the single identifier, and in fact I would still use the ObjectId to be the primary key on the collection.

But if I'm really not willing to keep ObjectId's in the URL, and the auto-increment IDs still need to be unique as well as scale - is there a better alternative given my needs?

Mase

unread,
Aug 31, 2012, 8:26:28 PM8/31/12
to mongod...@googlegroups.com
Yea tried this, but you only gain a bit, they're still long and ugly. It also produces characters that are not valid in a URL. 

Not preferable. Other ideas?

craiggwilson

unread,
Aug 31, 2012, 11:35:47 PM8/31/12
to mongod...@googlegroups.com
Do you have a natural key you can use?

Octavian Covalschi

unread,
Sep 1, 2012, 12:24:22 AM9/1/12
to mongod...@googlegroups.com
What about http://domain.com/your-seo-key-string/ab34134s24566asduy2

Do you think SE would care if at the end of url you'd add an objectId? The seo key would be any custom string you'd put there...

 My personal opinion though would be that url are less important for SEO. SEs got much smarter and it's more important the way you structure your content and not the actual url... As an example look at amazon's url, but I'm pretty sure results from amazon are't last one.

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Mase

unread,
Sep 8, 2012, 2:46:38 PM9/8/12
to mongod...@googlegroups.com
I will keep the original ObjectId as the primary key, I just need an additional integer key to use for URL purposes. Already got this in place for one of my most important dynamic pages, seems to be working well so far. But I don't have sharding or a large scale system yet either.

I understand that friendly URLs are only one part of an SEO strategy, but I'm definitely not Amazon. Putting the ObjectId at the end could work, and actually is better regardless of the size of my ID. 

Thanks guys... I think I'm set with my approach.
-Mason
Reply all
Reply to author
Forward
0 new messages