MongoDB backend

Does anyone know if there is a way to hook up a MongoDB Database to a test? I see in the Data Files that I can add a data base, but this seems to only be SQL based.

I’m going to try to do it through script in the editor, but just wanted to know if there was some built in way to do it first.


No way that I figured out. I just linked the mongoDB Java driver to the test and everything works just fine

1 Like

Hi Will York,
i am starting to read and write to Mongo. Currently i am using SQL db and working fine but i am new on connecting to Mongdb. In here, you seems to have succeeded in doing so, could i request for details on whats needed to coded ? i am using groovy… TIA

the tricky bit with mongo is how to find documents that have UUID in them…ive posted how ive manage to do it here

@ChewJin Koh

install the mongodb driver and connect to the mongo db through that…something like this

import com.mongodb.client.MongoCursor

import com.mongodb.MongoClient

import com.mongodb.BasicDBObject

import com.mongodb.DBObject

import com.mongodb.DBCursor

import com.mongodb.MongoCredential as MongoCredential

import com.mongodb.client.MongoCollection

import com.mongodb.client.MongoDatabase

import com.mongodb.MongoClientURI

import com.mongodb.client.result.DeleteResult

import com.mongodb.client.FindIterable

public class dataBaseMethods {

public static Connection connection

public static MongoDatabase db

public static MongoClient mongoClient


def mongoInitialize(String strConnectionString,String Database,String firstCollection){

mongoClient = null

String ClientURI = strConnectionString

MongoClientURI uri = new MongoClientURI(ClientURI)

mongoClient = new MongoClient(uri
db = mongoClient.getDatabase(Database)
MongoIterable collections = db.listCollectionNames()

1 Like

Will_York, since you was successful in connection and querying with MongoDB - can you share with me code sample (or custom keyword) with all your imports? TIA!

can somebody post an example how to connect to a mongoDB ?

1 Like


Using Mongo java driver 3.6.3 and bson 3.6.3 jar but can’t get past the error below:

com.mongodb.MongoQueryException: Query failed with error code 10307 and error message ‘’ on server
at com.mongodb.operation.FindOperation$
at com.mongodb.operation.FindOperation$
at com.mongodb.operation.OperationHelper.withConnectionSource(
at com.mongodb.operation.OperationHelper.withConnection(
at com.mongodb.operation.FindOperation.execute(
at com.mongodb.operation.FindOperation.execute(
at com.mongodb.Mongo$3.execute(
at com.mongodb.MongoIterableImpl.execute(
at com.mongodb.MongoIterableImpl.iterator(
at com.mongodb.MongoIterableImpl.forEach(
at com.mongodb.client.MongoIterable$forEach$ Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
at Connection.mongoInitialize(Connection.groovy:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.codehaus.groovy.reflection.CachedMethod.invoke(
at groovy.lang.MetaMethod.doMethodInvoke(
at groovy.lang.MetaClassImpl.invokeMethod(
at groovy.lang.MetaClassImpl.invokeMethod(
at groovy.lang.MetaClassImpl.invokeMethod(
at groovy.lang.DelegatingMetaClass.invokeMethod(
at Connection.invokeMethod(Connection.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
at com.kms.katalon.core.main.TestCaseExecutor.runScript(
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
at com.kms.katalon.core.main.TestCaseExecutor.execute(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(
at groovy.ui.GroovyMain.processOnce(
at groovy.ui.GroovyMain.process(
at groovy.ui.GroovyMain.processArgs(
at groovy.ui.GroovyMain.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(


Anyone has update on mongodb usage with Katalon.

~~ Thanks

Do you have any update on this ?

i keep getting errors on all the mongdb imports. were you able to get passed this?

How do you input your mongo query?

you need mongodb driver

Download the MongoDB driver from:

Does anyone able to get it worked in their Katalon projects?

I created a Keyword to connect to MongoDB using below code:

import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoClient;
import com.mongodb.MongoClientSettings;
import com.mongodb.ConnectionString;
import com.mongodb.ServerAddress;
import com.mongodb.MongoCredential;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import com.mongodb.client.FindIterable;

public class DBConnection {   	
	def connectMongoDB(String mongoURI, String dbase, String collectionName) {
		// Creating a Mongo client
		MongoClient mongoClient = MongoClients.create(mongoURI)
		// Accessing the database
		MongoDatabase database = mongoClient.getDatabase(dbase)
		println("\nConnected Successfully to Database: " +database)
		// Retrieving collections
		println('\nList of DB Collections in Database - "'+dbase+'" are: ');
		for (String collectionList : database.listCollectionNames()) {
			println("--	"+collectionList)
		// Connect to a Collection
		MongoCollection<Document> collection = database.getCollection(collectionName);
		println("\nConnected Successfully to Collection: " +collection)

Was able to connect to database successfully.
From here if wanted to create new Keywords (ex: getDocbyID ; getDocbyName etc) to get documents from above connected collection how do I do that? How do I use the above connected collection for next keyword?

For example next Keyword could be:

	def getDocumentByID(String OrgID) {
		//MongoCollection<Document> collection = connectMongoDB)()
		Document Org = collection.find(new Document("OrgID", 1)).first();
		println("Organization Doc: " + Org.toJson());

any ideas?

@nagendra.kuppala, how are you? did you manage to create the keywords getDocbyID, getDocbyName etc?