I'm trying to connect to MongoDB in Jmeter by using JSR223 Sampler. Here is my code:
import com.mongodb.MongoClientURI;
import com.mongodb.MongoClient;
import org.bson.Document;
import com.mongodb.BasicDBObject;
import com.mongodb.ConnectionString;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoClient;
import com.mongodb.MongoClientSettings;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import java.util.Arrays;
import com.mongodb.Cursor;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
try {
MongoClientURI connectionString = new MongoClientURI("mymongodb.com:27017");
MongoClient mongoClient = MongoClients.create(connectionString);
MongoDatabase database = mongoClient.getdatabse("mydatbase");
MongoCollection<Document> collection = database.getCollection("employee");
}
catch (Throwable ex) {
log.error("Error in Beanshell", ex);
throw ex;
}
I'm getting error:
ERROR o.a.j.p.j.s.J.JSR223 Sampler: Error in Beanshell groovy.lang.MissingMethodException: No signature of method: static com.mongodb.client.MongoClients.create() is applicable for argument types: (com.mongodb.MongoClientURI) values: [mymongodb.com:27017] Possible solutions: create(), create(com.mongodb.ConnectionString), create(com.mongodb.MongoClientSettings), create(java.lang.String), create(com.mongodb.ConnectionString, com.mongodb.MongoDriverInformation), create(com.mongodb.MongoClientSettings, com.mongodb.MongoDriverInformation) at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1518) ~[groovy-all-2.4.16.jar:2.4.16] at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504) ~[groovy-all-2.4.16.jar:2.4.16] at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:52) ~[groovy-all-2.4.16.jar:2.4.16] at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) [groovy-all-2.4.16.jar:2.4.16] at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) [groovy-all-2.4.16.jar:2.4.16] at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128) [groovy-all-2.4.16.jar:2.4.16] at Script11.run(Script11.groovy:44) [script:?] at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:321) [groovy-all-2.4.16.jar:2.4.16] at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) [groovy-all-2.4.16.jar:2.4.16] at javax.script.CompiledScript.eval(CompiledScript.java:89) [java.scripting:?] at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:223) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) [ApacheJMeter_core.jar:5.1.1 r1855137] at java.lang.Thread.run(Thread.java:834) [?:?]
Anyone has any ideas? Many Thanks!
ConnectionString
instead of aMongoClientURI
, prepend the protocolmongodb://
and feed that toMongoClients.create
? – alsMongoClientURI
and call theMongoClients.create
with"mogodb://mymongodb.com:27017"
– alsmongodb://
into the connection string. – als