0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/compactPreservePadding.js

26 lines
745 B
JavaScript

// test preservePadding
var collName = "compactPreservePadding";
var t = db.getCollection(collName);
t.drop();
// use larger keyname to avoid hitting an edge case with extents
for (i = 0; i < 10000; i++) {
t.insert({useLargerKeyName:i});
}
// remove half the entries
t.remove({useLargerKeyName:{$mod:[2,0]}})
printjson(t.stats());
originalSize = t.stats().size;
originalStorage = t.stats().storageSize;
// compact!
db.runCommand({compact: collName, preservePadding: true});
printjson(t.stats());
// object sizes ('size') should be the same (unless we hit an edge case involving extents, which
// this test doesn't) and storage size should shrink
assert(originalSize == t.stats().size);
assert(originalStorage > t.stats().storageSize);