Forum Discussion

ekta_sriv's avatar
New Contributor
6 years ago

Connect to mongo db using JDBC step

How to connect to Mongo DB using JDBC step in soap ui.


I have placed driver jar files(mongo-java-driver-3.4.2 and mongodb-driver-3.4.2) in bin/ext.


Below details are given in jdbc step


Driver: mongodb.jdbc.MongoDriver

Connection String: jdbc:mongodb://localhost:27017/Metro-Bank


But I am getting error as below while executing Failed to init connection for driver [mongodb.jdbc.MongoDriver], connectionString [jdbc:mongodb://localhost:27017/Metro-Bank]


Please guide me if we can connect to mongoDB using JDBC step in SOAP UI(free version)


1 Reply

  • Hi ekta_sriv ,


    Not sure about JDBC step but i have did the same using groovy with (mongo-java-driver-3.4.2) driver you can have a look at below code:


    import com.mongodb.MongoClient;
    import com.mongodb.MongoClientURI;
    String url = "mongodb://USER_NAME:PSWD@PORT/?authSource=AUTH_SOURCE&authMechanism=AUTH_MECHANISM"
    MongoClientURI client = new MongoClientURI(url);
    MongoClient mongoClient = new MongoClient(client);
    DB db = mongoClient.getDB("YOUR DB NAME"); 
    DBCollection collec = db.getCollection("YOUR DB COLLECTION NAME");
    BasicDBObject query = new BasicDBObject();
    //execute query
    def queryExec = collec.find(query);
    while (cursor.hasNext())
    //YOUR CODE to fetch values;