It is not easy to execute Mongo JS in the JDK because the original client has a JS library that wraps command calls to provide pretty syntax. The Java driver does the same job to provide an easy-to-use Java API.
You can use the Jongo library, which is designed to write Java code, similar to how you do it in the mongo shell.
If you want to run jon mongo mongo, you can do this using SSH for the MongoDB host or host with the mongodb client installed. (Include the mongo client executable in the application - a bad idea that blocks you in a specific version of the database). Here is an example of a simple shell providing a function call via ssh.
source share