The query that we run from a mongo-shell, I want to run the same query from a java program. How can I do that?
Asked
Active
Viewed 1,594 times
-3
-
Why use the shell from Java when you have proper bindings? – Hubert Grzeskowiak Nov 25 '15 at 17:06
-
1I think he is saying that he wrote some SQL query, it runs in the console (thus it's valid SQL etc) and now he wants to use the java bindings. – ventsyv Nov 25 '15 at 17:08
-
@Hubert Grzeskowiak, I have a plugin that take queries from mysql/oracle/cassandra etc and run into configured db dynamically. All the db configurations and the query to run is stored in data base. I want to enhance this plugin to support Mongo DB as well. – Sumit Bharati Nov 25 '15 at 17:24
-
The shell is probably only a wrapper around some libraries. If you need the functionality in your application/plugin, you probably want to use the same libraries instead of the user-oriented shell – Hubert Grzeskowiak Nov 25 '15 at 17:27
-
I had the same question I know how mongo works, but I was wondering too how you can run the same query that you develop/test via the shell in a program to ease debugging, sadly the answer seems to be you cannot, but this is still a valid question. – Cervo Apr 14 '16 at 01:04
1 Answers
0
I believe what you are looking for is mentioned in the comment in the answer to Create a Mongo query in Java using a String in that the library Jongo is what you are looking for. See http://jongo.org/ . Looks like not 100% the same e.g. db.collection.find(QUERY) becomes friends.find(QUERY) where query is a string. But it is closer than making the entire query into a DBObject.