开发者

mongoDB - URL as document ID

开发者 https://www.devze.com 2023-03-20 13:53 出处:网络
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

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

精彩评论

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