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

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

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

    paulwong

    How to delete large amount of data of a MongoDB collection “quickly”

    We have a db collection that is around 30 million documents, and I need to trim it down, to only keeping the documents created on the last month. 

    One approach would be use the remove command with a condition on the created_at field (the collection already have an index on this field):

    db.my_collection.remove({created_at: {$lte: new Date("11/01/2012")}});

    But this approach will be very slow, instead of that, a better way to do it is rename the current collection (for instance to “old_collection”) using renameCollection. Then performing a query-and-insert from the “old_collection” into “my_collection”:

    db.my_collection.renameCollection("old_collection");  
    db.createCollection("my_collection");
    db.my_collection.createIndex(...); // recreate the indexes for the collection
    // copy docs from old collection into the new collection
    db.old_collection.find(
    {created_at: {$gte: new Date("11/01/2012")}} ).sort({_id: -1}).forEach(
    function(row) { db.my_collection.insert(row); } ); // drop old collection db.old_collection.drop();

    This approach is typically faster than running a bunch of removes on your data

    posted on 2015-12-10 20:09 paulwong 閱讀(540) 評論(0)  編輯  收藏 所屬分類: MONGODB

    主站蜘蛛池模板: 四虎国产精品永久免费网址| 国产乱色精品成人免费视频| 亚洲高清国产拍精品熟女| 又爽又黄无遮挡高清免费视频| 日本黄色免费观看| a高清免费毛片久久| 九月丁香婷婷亚洲综合色| 四虎在线最新永久免费| 国产精品亚洲一区二区三区久久 | 中文字幕免费不卡二区| 亚洲午夜在线电影| 国产亚洲福利一区二区免费看| 亚洲中文字幕无码一去台湾| 亚洲国产成人久久精品99 | 亚洲精品美女在线观看| 毛片免费在线播放| 中文字幕在线观看免费| 亚洲国产区男人本色在线观看| 日本在线高清免费爱做网站| 人成免费在线视频| 中文日韩亚洲欧美制服| 亚洲国产美女精品久久久久∴| 国产一级黄片儿免费看| 亚洲综合激情五月丁香六月| 国产亚洲综合久久系列| 国产成人无码区免费A∨视频网站 国产成人涩涩涩视频在线观看免费 | 亚洲国产免费综合| 18禁男女爽爽爽午夜网站免费| 亚洲高清无在码在线电影不卡 | 亚洲综合色成在线播放| 最新中文字幕免费视频| 无码日韩精品一区二区三区免费| 国产亚洲精品精华液| 四虎永久免费地址在线网站| 久久午夜免费视频| 在线日本高清免费不卡| 成人无码精品1区2区3区免费看| 久久精品国产亚洲沈樵| 亚洲国产小视频精品久久久三级| 国产免费久久久久久无码| 国产成人亚洲精品电影|