开发者

mongoDB - URL as document ID

Considering I want to create mongoDB documents for a bunch of distinct UR开发者_StackOverflowLs: what would be the pros and cons (if any) of using the actual URL as the documents _id value instead of the default BSON ObjectId. Thanks in advance!

Cheers, Greg


An overview of the subject here: http://www.mongodb.org/display/DOCS/Object+IDs

It has to be unique, you could potentially put yourself in the position of having to resolve collisions yourself. Better to leave the default _id alone and simply query against a field you're storing in the document, just how God (10gen) intended.

From http://www.mongodb.org/display/DOCS/BSON

The element name "_id" is reserved for use as a primary key id, but you can store anything that is unique in that field. The database expects that drivers will prevent users from creating documents that violate these constraints.

From #mongodb

stupid _id values will probably make querying slow, but that's about it

And another user from #mongodb

Tell him the collisions will result in garbage data

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜