Hack ObjectId指示对象类型 [英] Hack ObjectId to indicate the object type

查看:89
本文介绍了Hack ObjectId指示对象类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过像这样操纵machineId来破解ObjectId:

I want to hack ObjectId by manipulating the machineId like this:

         <timestamp> <machineId> <processId> <inc>
UserId   XXXXXXXX    XXXX01      XXXX        XXXXXX
OrderId  XXXXXXXX    XXXX02      XXXX        XXXXXX
CardId   XXXXXXXX    XXXX03      XXXX        XXXXXX
...

基本思想是使用1字节的machineId来区分对象类型,我的问题是:这样做有什么问题(考虑唯一性和分片性)吗?

the basic idea is to use 1 byte of machineId to distinguish the object type, my question is: is there any problem when doing so (considering uniqueness and sharding)?

--- 12月9日更新---

由于规范和实现之间的差异为什么bson java实现使用4个字节的inc字段?,我将把解决方案稍微更改为以下样式:

Due to the difference between the spec and implementation Why the bson java implementation uses 4 bytes inc field?, I'm going to change my solution a bit to following style:

         <timestamp> <machineId> <processId> <inc>
UserId   XXXXXXXX    XXXX        XXXX        01XXXXXX
OrderId  XXXXXXXX    XXXX        XXXX        02XXXXXX
CardId   XXXXXXXX    XXXX        XXXX        03XXXXXX
...

推荐答案

假定两个字节的机器ID对于您的部署而言是足够唯一的,那应该没问题.好主意!

Assuming two bytes of machine id is sufficiently unique for your deployment, that should be fine. Neat idea!

这篇关于Hack ObjectId指示对象类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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