Facebook user_id 作为 MongoDB BSON ObjectId?
我正在与 Sinatra 和 Sinatra 重建 Facebook 上的情人雷迪斯。我喜欢 Redis,因为它没有长(12 字节)BSON ObjectIds ,我为每个用户存储 Facebook user_ids 集。这些集合是 requests_sent、requests_received 和 request_sent。关系,并且它们都包含 Facebook 用户 ID。
我正在考虑切换到 MongoDB,因为我想使用它的地理空间索引。如果这样做,我想使用 FB 用户 id 作为 _id 字段,因为我希望集合较小,并且希望 JSON 响应较小。但是,BSON ObjectId 是否比整数(fb user_id)更好(对于 MongoDB 更有效)?
I'm rebuilding Lovers on Facebook with Sinatra & Redis. I like Redis because it doesn'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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,没有重大的效率差异除了在某些情况下,例如按日期排序(因为 ObjectId 中包含日期时间等),
例如您' d 失去简单地通过 _id 订购的能力,您也会失去 分片和分发。除此之外,尽管我个人仍然会使用 ObjectId ...只要 int 不安静(当然)...你应该没问题。
由于_id总是在查询中“返回”,我想您会节省一点时间和数据传输(一点点)。
您甚至可以将您的_id设置为如果你想要的话,它会全部索引,很好地看到这个答案< /a> (并不是说大多数时候我一定会推荐这样做。)
另请参阅:优化对象 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