2

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

I have written java code to search/insert values into a collections in java.But what i want is that i have a .js file containing raw MongoDB queries ex:db.collectionname.find(fieldname: fieldvalue) and now i want to read the .js file line by line and execute the raw mongoDB queries. Please help me with any idea or about functions which will execute raw Mongo DB statements in java like statement.executequery("select * from tablename"); in sql

0

1 Answer 1

1

You could use a JSON intrepretter, like this one implemented in ANTLR, and output nested BasicDBObject's. The only remaining piece is parsing the db.collectionname.find(...), which should be relatively straightforward. Instead of ANTLR, you can also find one of probably many Java JSON parsers and instantiate the BasicDBObject's yourself.

Sign up to request clarification or add additional context in comments.

1 Comment

Mr.slee Actually i dont know whether you have mis-understood the question? Actually i have to simulate "pgsql databasename -f file.sql" in mongoDB or just read the raw mongoDb queries from a .txt/.js file and execute them via the javacode.if the above solution is also doing the same please explain in detail or just guide me with any other simple tutorials its above my head.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.