I have to fetch records from mongoDB using multiple threads and pass a different offset each time with limit as 100 to fetch 100 records eachtime. The following is the code that I've used in JSR223 Sampler with Groovy as the language selected. The problem faced here is that the StringBuilder takes too much time to parse the response, because of which the response time takes a hit.
Is there a better alternative as this approach doesn't seem right?
DB db = MongoDBHolder.getDBFromSource("<sourceConfigName>", "<db_name>");
DBCollection coll = db.getCollection("collection_name");
BasicDBObject query = new BasicDBObject("1st_field", "1st_value").append("2nd_field","2nd_value");
DBCursor cursor = coll.find(query).skip(${offset}).limit(100);
StringBuilder resultBuilder = new StringBuilder();
while (cursor.hasNext()) {
DBObject result = cursor.next();
resultBuilder.append(result.toString());
}
SampleResult.setResponseData(resultBuilder.toString().getBytes());