I'm rebuilding Lovers on Facebook with Sinatra & Redis. I like Redis because it doesn'开发者_Go百科t have the long (12-byte) BSON ObjectIds and I am storing sets of Facebook user_ids for each user. The sets are requests_sent, requests_received, & relationships, and they all contain Facebook user ids.
I'm thinking of switching to MongoDB because I want to use it's geospatial indexing. If I do, I'd want to use the FB user ids as the _id field because I want the sets to be small and I want the JSON responses to be small. But, is the BSON ObjectId better (more efficient for MongoDB) to use than just an integer (fb user_id)?
There are no major efficiency differences as far as I know except in certain cases like ordering by date (since the ObjectId's have the datetime in them, etc.)
For example you'd lose the ability to simply order by the _id you'd also lose the benefits for sharding and distribution. Aside from that, while I'd still personally use the ObjectId's anyhow ... as long as the int is unquie (of course) ... you should be just fine.
Since the _id always "comes back" in a query I suppose you'd save a little time and data transfer (a bitty bit.)
You can even make your _id an array if you wanted, and it'll all index nicely see this answer (not that I'd necessarily recommend that most of the time.)
Also see: Optimizing Object IDs
精彩评论