V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
whereabouts
V2EX  ›  程序员

顺序插入几万条数据到 MongoDB 未经修改 此时自动生成的_id 是不是越来越大的?

  •  
  •   whereabouts · Jul 2, 2018 · 2650 views
    This topic created in 2864 days ago, the information mentioned may be changed or developed.
    发现_id 是 bson.objectid 类型,可以用运算符比较大小,数据仓库写代码的时候忘记加.sort()排序就拿到_id 用了,想问下自动生成_id 的规则是不是越来越大的,是的话就不用回头再改程序了。。
    数据是顺序插入的,没有修改过。
    4 replies    2018-07-03 14:04:09 +08:00
    conn4575
        2
    conn4575  
       Jul 2, 2018   ❤️ 1
    是的,mongo 的 id 里面带有时间戳属性,所以可以保证越来越大,具体看一楼文档
    my3157
        3
    my3157  
       Jul 3, 2018
    copy from #1 url

    ```
    a 4-byte value representing the seconds since the Unix epoch,
    a 3-byte machine identifier,
    a 2-byte process id, and
    a 3-byte counter, starting with a random value.

    ```

    以上顺序拼起来之后 hex 就是常见到的 `5b375b5c44edb42181e15bbd`
    dlllcs
        4
    dlllcs  
       Jul 3, 2018
    并不是,同一秒同一机器的无法区分顺序,时间戳只保存到秒
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   985 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 23:17 · PVG 07:17 · LAX 16:17 · JFK 19:17
    ♥ Do have faith in what you're doing.