Scott Klarenbach
Scott Klarenbach

Reputation: 38771

mongodb java driver - raw command?

Is it possible to execute raw commands as javascript through the Java driver for MongoDB?

I'm tired of wrapping everything in Java objects using Rhino, and would happily sacrifice performance for the convenience of passing javascript directly through to the DB.

If not, I can always use sleepymongoose or something, but I don't really want to add yet another language (python) to the stack at this point.

Any insights are appreciated.

Upvotes: 4

Views: 8433

Answers (2)

alex
alex

Reputation: 114

actually no. This command(String) can run any kind of mongo database commands, not arbitrary javascript. For the latter you would need DB.eval() which would block your whole DB unless you are using 1.7.2 mongo or later and the noblock option set.

references: http://api.mongodb.org/java/2.4-rc0/index.html http://mongodb.onconfluence.com/display/DOCS/List+of+Database+Commands

Upvotes: 7

Carnell
Carnell

Reputation: 749

There are 2 DB.command() methods in the mongo java driver. One of the 2 takes a String. I think this is what you are looking for.

See here

Upvotes: 0

Related Questions