开发者

Generating secondary Uniqie Id's Mongodb

开发者 https://www.devze.com 2023-04-11 20:15 出处:网络
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 havi

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

精彩评论

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