I attempted to establish a connection between JMeter and MongoDB using JavaScript as the scripting language, but encountered failures.
The same code worked successfully in Node JS, however, it fails when implemented in JMeter.
var mongo = require('mongodb');
var MongoClient = mongo.MongoClient;
var url = 'mongodb://10.80.47.101:27017';
MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => {
if (err) throw err;
const db = client.db("scorecard");
db.listCollections().toArray().then((docs) => {
console.log('Available collections:');
docs.forEach((doc, idx, array) => { console.log(doc.name) });
}).catch((err) => {
console.log(err);
}).finally(() => {
client.close();
});
});
An error is being thrown while running this script in JMeter:
Response code: 500 Response message: javax.script.ScriptException: :9:6 Expected : but found ( if (err) throw err; ^ in at line number 9 at column number 6