<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 閱讀(255) 評論(0)  編輯  收藏 所屬分類: DB

    主站蜘蛛池模板: 亚洲色丰满少妇高潮18p| 亚洲午夜精品国产电影在线观看| 亚洲熟妇无码八V在线播放| 99re热精品视频国产免费| 色婷婷六月亚洲婷婷丁香| 久久久久国产精品免费免费不卡 | 精品亚洲av无码一区二区柚蜜| 日韩在线免费视频| 在线观看亚洲AV日韩AV| 女人18毛片水真多免费看| WWW亚洲色大成网络.COM| 亚洲日本一区二区三区在线不卡| 一个人看的www免费在线视频| 国产亚洲精品拍拍拍拍拍| 三年片在线观看免费西瓜视频 | 亚洲国产精品综合久久久| 又黄又爽又成人免费视频| 亚洲熟女乱色一区二区三区| 国产一级理论免费版| 一个人看的www在线免费视频| 亚洲人成人无码网www电影首页| a国产成人免费视频| 亚洲av乱码一区二区三区香蕉| 日韩在线免费播放| 一级黄色毛片免费看| 亚洲人成网站在线播放影院在线| 日韩不卡免费视频| 免费手机在线看片| 亚洲日本一区二区三区| 亚洲人成电影网站免费| 美女露100%胸无遮挡免费观看| 国产亚洲一区二区手机在线观看| 最好看的中文字幕2019免费| 亚洲性色AV日韩在线观看| 亚洲最大av无码网址| 精品国产无限资源免费观看| 欧美色欧美亚洲另类二区| 亚洲AV人无码激艳猛片| 免费无码一区二区三区蜜桃大| 中文在线免费不卡视频| 精品亚洲成A人无码成A在线观看|