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

    主站蜘蛛池模板: 老司机亚洲精品影院在线观看| 亚洲精品亚洲人成在线观看麻豆 | 国产精品成人免费观看| 日本免费人成视频播放| 亚洲AV女人18毛片水真多| 女人张开腿等男人桶免费视频| 亚洲中文字幕久久精品无码A | 日本视频免费高清一本18| 人人狠狠综合久久亚洲88| 97超高清在线观看免费视频| 亚洲成AV人片在线观看无| 国产成人AV片无码免费| 久久精品国产精品亚洲毛片| 精品成在人线AV无码免费看| 亚洲第一成年人网站| 午夜视频在线在免费| 色网站在线免费观看| 亚洲伊人久久大香线蕉综合图片| 99免费在线视频| 久久亚洲精品无码aⅴ大香| 性xxxxx免费视频播放| 亚洲av无码成人精品区一本二本 | 免费无码黄网站在线观看| 国产成人精品亚洲| 国产午夜亚洲精品理论片不卡 | 国产三级在线免费观看| 亚洲大成色www永久网站| xxxx日本免费| 免费的黄网站男人的天堂| 国产亚洲精品精华液| 日本免费网址大全在线观看 | 免费看成人AA片无码视频吃奶| 亚洲av无码不卡| 免费毛片在线看片免费丝瓜视频| 免费在线观看亚洲| 日韩亚洲一区二区三区| 青青视频观看免费99| 国产精品免费久久久久久久久 | 伊人久久亚洲综合影院| 无码少妇精品一区二区免费动态 | caoporm碰最新免费公开视频|