开发者

Generating secondary Uniqie Id's Mongodb

I have been trying to find a way to generate unique Id's in mongodb. I know that mongodb has _id which is unique based on time which server its beeing added to among other things. The issue I am having is I need simple ID's for things like users. I know that I could have a collection just for keeping track of these id's that I want but I am afried that when mongodb is in 开发者_StackOverflow社区a cluster (sharing and failover) that there is a chance that the same number could be generated twice and in that case to things would have the same id in my system.

I was thinking of setting up a PostgreSQL server up just for handling id generation. ALL it would do is insert a new row and return the id of that new row and then once a day it could easily wipe all date other then what the next key it needs to generate. Does anyone have any other suggestions.

Just to let you know i am using PHP.


bson ObjectId's in mongodb will be unique cluster-wide. thus that is safe.

see also Sequence Numbers on the following page; ObjectId is preferred (scales best) : http://www.mongodb.org/display/DOCS/Object+IDs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜