I successfully implemented the MongoDB connection in my Node.js application, however, it is unfortunately experiencing issues when tested with JMeter

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

Answer №1

  1. The functionality of executing JavaScript in JMeter is constrained to the Nashorn engine, causing scripts using 'require' from Node.js to fail on the first line.
  2. Since version 3.1 of JMeter, it is advised against using languages other than Groovy for scripting purposes.

Instead of attempting to load test your Mongo instance with JavaScript code, consider the following steps:

  1. Obtain the MongoDB Java Driver corresponding to your Mongo version and add it to the JMeter Classpath.
  2. Restart JMeter to apply the changes.
  3. Include a JSR223 Sampler in your Test Plan.
  4. Develop your logic in Groovy, referring to the JavaDoc of your specific Mongo Java Driver version for correct syntax.

For further details, read: MongoDB Performance Testing with JMeter

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on choosing one specific JSON object from a group and exploring its structure in Python

Looking for guidance to access a specific javascript element named SOURCE.pdp.propertyJSON and extract its attributes in a Pythonic way from a webpage filled with different script elements. Browse through the HTML source code below to get an idea and then ...

Dynamic Pagination with MUI Counting

I'm currently utilizing mui react for my current project. Within the Pagination component, I am required to input the count in order to display the total number of pages. For example, with a total of 27 products, and each page displaying 20 products ...

Display the iframe website without it being visible to the user

Is there a way to load a separate website, such as a Wikipedia article, in an iframe on a webpage without freezing up the whole page when it becomes visible after clicking a "show" button? And if not, how can we display a loading gif while the iframe is ...

Discovery of altered entity in integration test reveals previous values

I have a specific repository setup as shown below: @Repository public interface UserRepository extends JpaRepository<User, String> { Optional<User> findUserByUniqueName(String uniqueName); } During an integration test, I update the uni ...

Leveraging various libraries in React

My query revolves around a React application where I have integrated Material UI for only two components. Despite installing the entire Material UI library, will this lead to an increased bundle size for my application? Or does the build process only inc ...

Having issues with a drop-down in Bootstrap. Is there anyone who can assist in getting it to function

I recently implemented a drop-down menu on the top navigation of my website. However, after applying Bootstrap to one of my pages, the drop-down menu stopped functioning properly. Below is the code that was applied: <link href="https://cdn.jsd ...

Ways to compel Capacitor Application to reload through code

Is there a way to programmatically restart my app so that it functions seamlessly across all platforms - electron, iOS, Android, and web? If so, how can I make this happen? ...

Reverse direction in Android Studio

Working on my Android Studio app development, I'm facing an issue with element placement on the screen. For instance, I'm attempting to position a button on the right side of the screen in the Studio view, but once I install the app on my smartp ...

HTML code is shown as plain text instead of being rendered as a webpage

Hey there! I'm embarking on a journey to integrate APIs into my project for creating a Weather reporting system. Check out my .js script below: const express = require("express"); const bodyParser = require("body-parser"); const https = require("https ...

Display a block by using the focus() method

My objective is : To display a popin when the user clicks on a button To hide the popin when the user clicks elsewhere I previously implemented this solution successfully: Use jQuery to hide a DIV when the user clicks outside of it However, I wanted to ...

Navigating through Routing Express and sending data to a template

If I have the following code in my router.get() function, how can I output a template with the data without being able to use res.render()? router.get('/read', function(request, response) { res.send({"result": "Success sent from routes/index ...

The $(document).ready function may not be compatible with Internet Explorer

I have a page with two links - one for registering and one for logging in. Currently, the register link is the most important. When clicked, it loads a .tpl file using jQuery's load function. Within this tpl file, I include a new JavaScript file usin ...

Updating an element's HTML content from a template URL using AngularJS

Can someone help me figure out how to set the html of an element in my directive based on a dynamic template url? element.html('some url to a template html file'); rather than using element.html('<div>test</div>').show() ...

navigating through an array with a loop (for)

I created a basic phone book program where users can input a name and it will search an array of objects for the corresponding phone number. If the name is found, it will display the name and phone number. However, I am facing an issue where even though ...

Sorting after grouping in AngularJS is a breeze

After using lodash.js groupBy to organize my collection, the order is correct when I log it with console.debug. However, when I try to display it in the UI using ng-repeat, the ordering gets messed up. var list = [{id:1,categoryId:1,name:test1}, ...

JavaScript code may fail to load on initial page load

My JavaScript function utilizes ajax and is triggered when a button is clicked. Oddly, the function works perfectly if you visit the page for a second time, but fails to work on the first visit. I've attempted to include window.onload, document.onlo ...

Activate the button in React after ensuring all form fields are populated

Hello everyone, I'm new to using React and I'm trying to implement some basic validation but I'm struggling. Here are my goals: Disable the button if any form fields are empty Enable the button only when ALL form fields are are filled I w ...

Python Flask server integrated with MongoDB using flask-pymongo

My objective is to establish a flask server that adds data/users to a mongoDB database. The initial setup of the DB (using mongo shell) was executed in the following manner: >use dbname switched to dbname >db.users.save( {username:"user", passwo ...

Deactivate a link within a specific element depending on the content of another element

I have a table with multiple rows. One column contains links (column a) and the other column displays either "Yes" or "No" (column b). If a cell in column b shows "No", I want to disable the link in the cell directly to its left in column a. I am using t ...

Is Cookie-session the most ideal choice for React applications?

My NodeJS application currently authenticates users through a third-party app. Once the app retrieves user data, a cookie is generated and sent to the client for React to access the user data from that Cookie. Should I stick with using cookies or consi ...