Are there any reasons why I should/shouldn't use ObjectId's in my RESTful url's

后端 未结 2 470
青春惊慌失措
青春惊慌失措 2020-12-05 19:42

I\'m using mongoDB for the first time in a RESTful service. Previously the id column in my SQL databases was an incrementing integer so my RESTful endpoints would look somet

2条回答
  •  既然无缘
    2020-12-05 20:15

    It's wiser to use the ObjectIds, because keeping an incrementing counter can be a bottleneck. Also, since ObjectId contains a timestamp and is monotonic, they can be helpful in optimizing queries.

    The ObjectIds can be guessed, but since that is definitely true for incrementing IDs, I suspect you didn't rely on security through obscurity before, so that's no trouble for you.

    A downside, albeit a small one, is that the creation time on your server leaks to the user, i.e. if the user is able to identify this as an ObjectId, she can reverse-engineer the creation time of the object. That's the only potential issue I see.

提交回复
热议问题