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

    主站蜘蛛池模板: 国产成人yy免费视频| 亚洲精品9999久久久久无码| 国产成人无码综合亚洲日韩| 亚洲一区二区精品视频| 亚洲av无码成人精品区| 最好免费观看韩国+日本| 国产人在线成免费视频| 日韩免费精品视频| 国产成人午夜精品免费视频| 免费无码黄十八禁网站在线观看| 99久久免费国产香蕉麻豆| 国产片AV片永久免费观看| 久久精品a一国产成人免费网站| 97性无码区免费| 我要看WWW免费看插插视频| 免费涩涩在线视频网| 国产18禁黄网站免费观看| 亚洲国产成人久久笫一页| 亚洲熟妇丰满多毛XXXX| 水蜜桃亚洲一二三四在线 | a毛片免费播放全部完整| 你懂的网址免费国产| 在线观看免费av网站| 欧美日韩国产免费一区二区三区| 暖暖在线日本免费中文| 免费午夜爽爽爽WWW视频十八禁 | 国产精品视频永久免费播放| 四虎www免费人成| 亚洲国产精品成人网址天堂| 亚洲精品无码久久一线| 亚洲综合亚洲国产尤物| 亚洲精品无码久久| 国产精品玖玖美女张开腿让男人桶爽免费看 | 国产网站在线免费观看| 亚洲精品偷拍视频免费观看| 国产亚洲色婷婷久久99精品| 亚洲国产成人久久精品app| 国产精品无码亚洲精品2021| 久青草视频97国内免费影视| 最近2019中文字幕免费直播| 免费鲁丝片一级观看|