cancel
Showing results for 
Search instead for 
Did you mean: 

Connect to mongo db using JDBC step

Highlighted
New Contributor

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

 

com.eviware.soapui.support.SoapUIException: 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 1
Highlighted
Community Leader

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();
query.append("some_parameter",value);

//execute query
def queryExec = collec.find(query);
while (cursor.hasNext())
{
//YOUR CODE to fetch values;
}

mongoClient.close();

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors