Skip to content

Instantly share code, notes, and snippets.

@Sheeri
Last active May 18, 2020 16:13
Show Gist options
  • Save Sheeri/2c146496f88ffb9e90b372838adb06a1 to your computer and use it in GitHub Desktop.
Save Sheeri/2c146496f88ffb9e90b372838adb06a1 to your computer and use it in GitHub Desktop.
mdb wa load test
'use strict';
function getRandomString(length) {
let s = '';
while (s.length < length && length > 0) {
const r = Math.random();
if (r < 0.1) {
s += Math.floor(r * 100);
} else if (r > 0.5) {
s += String.fromCharCode(Math.floor(r * 26) + 97);
} else {
s += String.fromCharCode(Math.floor(r * 26) + 65);
}
}
return s;
}
// eslint-disable-next-line no-undef
const OceanWatch = db.getSiblingDB('OceanWatch');
OceanWatch.setProfilingLevel(0, -1);
// eslint-disable-next-line no-unused-vars
let x;
const numsaildroneIOTDocuments = 10e3;
const numIterations = 100;
for (let i = 0; i < numIterations; i++) {
if (i % (numIterations / 10) === 0) {
// eslint-disable-next-line no-console
print(`${(i / numIterations) * 100}% complete running queries`);
}
// nScanned/nReturned will be numsaildroneIOTDocuments : 1
x = OceanWatch.saildrone.find({ 'timeUTC': {$gt: ISODate('2019-10-01 00:00:00')}});
x.hasNext();
// nScanned/nReturned will be numsaildroneIOTDocuments : 1
x = OceanWatch.saildrone.aggregate([{ $match: { TEMP_CTD_RBR_MEAN: {$gt: 25.7 }} },{$sort: { timeUTC: 1 }}],{ "allowDiskUse" : true });
x.hasNext();
// nScanned/nReturned will be numsaildroneIOTDocuments : 0
// eslint-disable-next-line no-undef
x = OceanWatch.saildrone.aggregate([{ $match: { RH_MEAN: {$gt: 60.3 }} },{$sort: { timeUTC: 1 }}],{ "allowDiskUse" : true });
x.hasNext();
x = OceanWatch.saildrone.findAndModify({
query: {
trajectory: 1066
},
update: {
$set: { trajectory: 6601 }
}
});
x = OceanWatch.saildrone.findAndModify({
query: {
trajectory: 6601
},
update: {
$set: { trajectory: 1066 }
}
});
const a = numIterations - i;
// x.hasNext();
// OceanWatch.saildrone.remove({ a: Math.floor(Math.random() * numsaildroneIOTDocuments) });
x = OceanWatch.saildrone.aggregate( { $match: { RH_MEAN: {multiply: [Math.random(), 70]} } });
x.hasNext();
x = OceanWatch.saildrone.find({
"coordinates.latitude": {$lt: 2},
arrayOperation: { $in: [i, i + 1, i + 2, i + 3] },
date: new Date(0),
// eslint-disable-next-line no-undef
binary: new BinData(0, 'abcd'),
// eslint-disable-next-line no-undef
id: new ObjectId("000000000000000000000000"),
embeddedDocument: {
a: 1,
b: 2,
c: 3,
},
embeddedArray: [1, 2, 3, 4],
embeddedDocumentArray: [{ [`a${i}`]: 1 }, { [`b${i}`]: 2 }, { [`c${i}`]: 3 }],
embeddedArrayDocument: {
a: [1, 2, 3, 4],
b: [{ [`a${i}`]: 1 }, { [`b${i}`]: 2 }],
},
nullValue: null,
decimal: 12345.67890,
regex: /asdf/i,
'nested.field': 'abcd',
quotedReservedWordField: '{command}',
});
x.hasNext();
}
OceanWatch.setProfilingLevel(0, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment