0
votes

I am trying to call a method from java to connect to the mongoDB database, my machine can do it successfully but if I run it with a different one, I get this error.

2020-07-15 12:57:21,751 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import test.MongoDB; MongoDB.connect(vars.get("uri"));'' : Method Invocation MongoDB.connect

What could be the problem?

java


import java.util.LinkedHashMap;
import java.util.Map;

import org.bson.Document;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

public class MongoDB {

    public static MongoDatabase database;
    public static MongoClient mongoClients;

    public static void connect(String uri) {

        MongoClientURI uri_1 = new MongoClientURI(uri);
        // Connecting With Server
        mongoClients = new MongoClient(uri_1);
        System.out.println("server connection successfully done");

        database = mongoClients.getDatabase("Capacitacion");
        System.out.println("Connect to database successfully");
        System.out.println("DataBase Name: " + database.getName());
        MongoCollection<Document> col_Capacitacion_Liceo = database.getCollection("Liceo");


    } ```



jmeter

```import test.MongoDB;

MongoDB.connect(vars.get("uri"));;```
*
1

1 Answers

0
votes

Beanshell is not Java and it doesn't support Diamond Operators

If for some reason you really need to use Beanshell - change this line:

 MongoCollection<Document> col_Capacitacion_Liceo = database.getCollection("Liceo");

to this one:

MongoCollection col_Capacitacion_Liceo = database.getCollection("Liceo");

But be aware that starting from JMeter 3.1 users are encouraged to use JSR223 Test Elements and Groovy language for scripting.

You may also find MongoDB Performance Testing with JMeter article useful