Skip to content

Instantly share code, notes, and snippets.

@ttrelle
Last active January 29, 2016 10:39
Show Gist options
  • Save ttrelle/ef6d56ec023fd64a8e90 to your computer and use it in GitHub Desktop.
Save ttrelle/ef6d56ec023fd64a8e90 to your computer and use it in GitHub Desktop.
MongoDB File Allocation Test
var DATA = "12345678";
var c = db.getCollection("volume");
function insert(n) {
var s = data();
for (i=0; i<n; i++) {
if (i%200 == 0) {
print(i);
}
var wr = c.insert({_id:i, s: s});
if (wr && wr.nInserted != 1) {
print(i + ": " + tojson(wr));
}
}
showCount();
}
function removeEven(n) {
for (i=0; i<n; i++) {
if (i%2 == 0) {
c.remove({_id:i});
}
}
showCount();
}
function data() {
var s = DATA;
for (i=0; i < 2048; i++) {
s += DATA;
}
return s;
}
function showCount() {
print("Number of records: " + c.count());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment