Store _Id as object or string in MongoDB?

后端 未结 2 1619
春和景丽
春和景丽 2020-12-08 15:24

I am developing an API using Codeigniter and MongoDB. In this system I am saving the full name and _ID of users that the selected user is following.

What is best to

相关标签:
2条回答
  • 2020-12-08 15:51

    Performance for requests (and updates) are really better with objectid. More over, objectid are quite small in space.

    From the official doc :

    BSON includes a binary data datatype for storing byte arrays. Using this will make the id values, and their respective keys in the _id index, twice as small.

    here are 2 links that can help you : - http://www.mongodb.org/display/DOCS/Optimizing+Object+IDs - http://www.mongodb.org/display/DOCS/Object+IDs

    0 讨论(0)
  • 2020-12-08 15:53

    When you use ObjectId, it generates _id as a unique value in all your computers. So if you use Sharding, you will not worry about you _id conflicts. See how ObjectId generates in specification
    But if you use string, you should generate it carefully.

    0 讨论(0)
提交回复
热议问题