This method uses mongoclient to connect to the mongodb database and execute a query. This shows how to execute a query and run a test using TestNG with data from mongodb database and that can be used further for any assertion in database testing automation. While writing the method we used localhost as a sample mongo url. This is just a sample database connection and validation. You can change it to suite your requirement.