Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB (Java) - How to run query saved in javascript file?

So I have a lot of .js files that I have used to query MongoDB from the Command Line Interface before, but now I want to be able to run those same queries through Java (I am using Java to back a web interface that relies on the information from the query). How can I use those JavaScript queries from the Java driver and return some data that I can work with (the end game is to format the result into HTML, if that helps).

like image 322
Sam Stern Avatar asked Dec 19 '25 05:12

Sam Stern


2 Answers

If you need to executye your js files during buildtime, you can use maven-mongodb-plugin. This plugin uses db.eval()...

like image 121
Benoît Guérout Avatar answered Dec 21 '25 19:12

Benoît Guérout


using Java IO to read your js files, filter the queries , execute the queries.

like image 32
brian_wang Avatar answered Dec 21 '25 19:12

brian_wang