Facebook user_id为MongoDB BSON ObjectId? [英] Facebook user_id as MongoDB BSON ObjectId?

查看:134
本文介绍了Facebook user_id为MongoDB BSON ObjectId?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重建 Facebook上的恋人,与Sinatra& Redis的。我喜欢Redis,因为它没有长(12字节)的 BSON ObjectIds ,我正在为每个用户存储一组Facebook user_ids。这些集合是requests_sent,request_received和&关系,他们都包含Facebook用户ID。

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.

我正在考虑切换到MongoDB,因为我想使用它的地理空间索引。如果我这样做,我想使用FB用户ID作为_id字段,因为我希望这些集合很小,并且我希望JSON响应是小的。但是,BSON ObjectId是否比MongoDB更好(对于MongoDB更有效)而不仅仅是一个整数(fb user_id)?

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)?

推荐答案

在某些情况下,除了 之外,我知道 没有重大的效率差异,例如按日期排序(因为ObjectId的日期时间等等)

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.)

例如,您将失去通过 _id 进行排序的功能,您也将失去分片和分发。除此之外,尽管我仍然亲自使用ObjectId无论如何 ...只要 int 是不安的(当然)...你应该很好

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.

由于 _id 在查询中总是回来,我想你会节省一点时间和数据传输(一点点。)

Since the _id always "comes back" in a query I suppose you'd save a little time and data transfer (a bitty bit.)

你甚至可以使你的 _id 一个数组,如果你想要的,它会很好地查看这个 answer (不是我一定会建议大部分时间。)

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.)

另请参阅:优化对象ID

这篇关于Facebook user_id为MongoDB BSON ObjectId?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆