Facebook user_id like MongoDB BSON ObjectId?

I am rebuilding Lovers on Facebook with Sinatra and Redis. I like Redis because it does not have a long (12-byte) BSON ObjectIds , and I store user sets user_ids for each user. Sets are request_sent, request_received and relationships, and all of them contain Facebook user IDs.

I am going to switch to MongoDB because I want to use its geospatial indexing. If I do this, I would like 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 it better to use the BSON ObjectId (more efficient for MongoDB) than just an integer (fb user_id)?

+4
source share
1 answer

There are no significant differences in performance, as far as I know, except in some cases, such as ordering by date (since ObjectId has a date-time in them, etc.)

For example, you lose the ability to simply order with _id , you also lose the benefits of sharding and distribution . Also, although I still personally used ObjectId anyway ... as long as int is not sure (of course) ... you should be fine.

Since _id is always "returned" in the request, I suppose you would save a little time and data transfer (bit bit).

You can even make your _id array if you want, and all of this will be fine to see this answer (not that I'd definitely recommend this most of the time.)

Also see: Optimizing Object Identifiers

+2
source

Source: https://habr.com/ru/post/1334788/


All Articles