<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Chan Chen Coding...

    Optimizing Object IDs

    The _id field in a MongoDB document is very important and is always indexed for normal collections. This page lists some recommendations. Note that it is common to use the BSON ObjectID datatype for _id's, but the values of an _id field can be of any type.

    Use the collections 'natural primary key' in the _id field.

    _id's can be any type, so if your objects have a natural unique identifier, consider using that in _id to both save space and avoid an additional index.

    When possible, use _id values that are roughly in ascending order.

    If the _id's are in a somewhat well defined order, on inserts the entire b-tree for the _id index need not be loaded. BSON ObjectIds have this property.

    Store Binary GUIDs as BinData, rather than as hex encoded strings

    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.

    Note that unlike the BSON Object ID type (see above), most UUIDs do not have a rough ascending order, which creates additional caching needs for their index.

    > // mongo shell bindata info: 
    > help misc
        b = new BinData(subtype,base64str)     create a BSON BinData value     
        b.subtype()     the BinData subtype (0..255)
        b.length()     length of the BinData data in bytes
        b.hex()     the data as a hex encoded string
        b.base64()     the data as a base 64 encoded string
        b.toString()
    Extract insertion times from _id rather than having a separate timestamp field.

    The BSON ObjectId format provides documents with a creation timestamp (one second granularity) for free. Almost all drivers implement methods for extracting these timestamps; see the relevant api docs for details. In the shell:

    > // mongo shell ObjectId methods 
    > help misc
        o = new ObjectId() create a new ObjectId
        o.getTimestamp() return timestamp derived from first 32 bits of the OID
        o.isObjectId()
        o.toString()
        o.equals(otherid)
    Sort by _id to sort by insertion time

    BSON ObjectId's begin with a timestamp. Thus sorting by _id, when using the ObjectID type, results in sorting by time. Note: granularity of the timestamp portion of the ObjectID is to one second only.

    > // get 10 newest items 
    > db.mycollection.find().sort({id:-1}).limit(10);


    -----------------------------------------------------
    Silence, the way to avoid many problems;
    Smile, the way to solve many problems;

    posted on 2012-02-27 14:06 Chan Chen 閱讀(261) 評論(0)  編輯  收藏 所屬分類: DB

    主站蜘蛛池模板: 免费观看激色视频网站bd| 久久久国产亚洲精品| 成年大片免费视频| 99re免费视频| 国内精品免费视频精选在线观看| 亚洲中文无码a∨在线观看| 亚洲精品综合一二三区在线| gogo全球高清大胆亚洲| 最近中文字幕国语免费完整 | 一出一进一爽一粗一大视频免费的| 亚洲三级在线免费观看| 亚洲视频一区在线| 亚洲性69影院在线观看| 亚洲福利在线视频| 亚洲毛片在线免费观看| 亚洲国产精品成人综合久久久 | 免费国产成人高清在线观看麻豆 | 日韩免费高清大片在线| 日本一区二区三区免费高清| 亚洲一级免费毛片| 成人免费毛片观看| 亚洲国产综合精品一区在线播放| 免费国产高清视频| 亚洲区小说区图片区QVOD| 亚洲色图国产精品| 亚洲人片在线观看天堂无码| 亚洲老熟女五十路老熟女bbw| 免费无毒a网站在线观看| 久久免费高清视频| 午夜精品在线免费观看| 色久悠悠婷婷综合在线亚洲| 亚洲高清美女一区二区三区| 亚洲6080yy久久无码产自国产| 国产99视频精品免费视频76 | 亚洲导航深夜福利| 国产伦精品一区二区免费| 无码国产精品一区二区免费式直播| 国产大片免费观看中文字幕| 亚洲欧洲另类春色校园小说| 一级毛片免费视频网站| 成人啪精品视频免费网站|