MongoDB code sample needed for performing connection & queries

Hi there! I’ve discovered that there are few topics with same questions, but there was no clarification for me. Please, provide any full (with imports) samples of code (custom keyword implementation, test case script implementation). My previous project was on PostgreSQL and I’ve implemented via custom keyword connection, query & disconnection. But now with MongoDB I’m totally confused - I’ve downloaded the “mongo-java-driver-3.9.1.jar” and put it in the Drivers folder of my project, but how to import and use it in scripts…Thanks in advance!

You have to restart Katalon studio when you add a new driver into Drivers.
Then, you can import 3rd party libraries (according to MongoDB driver documentation).

Thanks, Marek! I’ve already done what you meant, but what about import? Cuz when I was using custom keyword for automation two-factor authentication (aerogear-otp-java-1.0.0.jar) I’ve an import “import org.jboss.aerogear.security.otp.Totp”. So, can you provide any code examples with imports and other stuff to connecting and querying MongoDB. TIA!

Unfortunately, I have no experience with MongoDB in Java. But try to follow official documentation:

https://www.mongodb.com/blog/post/getting-started-with-mongodb-and-java-part-i

Hi Ivan, did you ever figure it out? I need to run a mongo query and can’t figure out how to pull in mongo. I get unable to resolve class errors.

1 Like

i am getting the same errors. anyone figure this out yet?