1 in-Shell for loop cleanup
Remove the data by connecting MONGO each time
echo "Begin ..." >>/root/time.log;echo $ (date +%y-%m-%d-%h:%m:%s) >>/root/time.log;for (i=1;i<= 100000000;i++)); Do objectid= '/usr/local/mongodb/bin/mongo 127.0.0.1:37017/test-uadmin-padmin--quiet--eval "Printjson ( Db.tickets.findOne ({"date": {\ \ $lt: Isodate (\ "2013-01-10t01:16:33.303z\")}},{"_id": 1}) "'; /usr/local/mongodb/bin/mongo 127.0.0.1:37017/test-uadmin-padmin--quiet--eval "Db.tickets.remove ($objectid)"; echo "Done" $objectid " " >>/root/tickets.logdoneecho $ (date +%y-%m-%d-%h:%m:%s) >>/root/time.log; echo "End ..." >>/root/time.log;echo "" >>/root/time.log
2 MONGO shell in for loop cleanup
Connect only once MONGO, in MONGO shell for loop cleanup
[Email protected] ~]# more T.shecho "Begin ..." >>/root/t.log;echo $ (date +%y-%m-%d-%h:%m:%s) >>/root/t.log ;/usr/local/mongodb/bin/mongo 127.0.0.1:37017/test-uadmin-padmin T.js;echo $ (date +%y-%m-%d-%h:%m:%s) >>/root /t.log;echo "End ..." >>/root/t.log;echo "" >>/root/t.log[[email protected] ~]# [[email protected] ~]# [[EM AIL protected] ~]# more t.jsfor (var i=1; i<=100000000; i++) { var objectid = Db.tickets.findOne ({date:{$lt: Isoda Te ("2013-01-10t01:16:33.303z")}},{_id:1}); Db.tickets.remove (Objectid);} [Email protected] ~]#
The actual test, the first kind of security insurance more, but after all slow, clean up 100G of data about 3 days, the second kind of fast (said to be risky, but I did not hit the test), clean up 100G of data, spent 6 hours.
2 ways MongoDB cleans up large amounts of data in collection