Skip to content

Instantly share code, notes, and snippets.

@aharbick
Created April 14, 2011 17:33
Show Gist options
  • Save aharbick/920015 to your computer and use it in GitHub Desktop.
Save aharbick/920015 to your computer and use it in GitHub Desktop.
If you drop a capped collection and re-create it with different size params then data files never get cleaned up.
require 'pp'
@conn = Mongo::Connection.new
def randomString (string_length)
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
randomstring = '';
0.upto(string_length) do
rnum = (rand * chars.size).floor
randomstring += chars.slice(rnum,rnum+1);
end
return randomstring;
end
@size = 10000000
0.upto(100) do
@conn.db('capped_test').create_collection('capped', {:capped => true, :size => @size, :max => 10000})
# Report storageSize and fileSize
pp "storageSize: #{@conn.db('capped_test').collection('capped').stats['storageSize']}"
pp "fileSize: #{@conn.db('capped_test').stats['fileSize']}"
pp "-----------------------------------"
# Save the current storageSize for next iteration through the loop
@size = @conn.db('capped_test').collection('capped').stats['storageSize']
# Drop our collection
@conn.db('capped_test').collection('capped').drop()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment