java - Updating to mongo 3.0 -


i working on mongo 2.x , have updated mongo 3.x updated java mongodb client 3.0.3, have js on mongo server needs executed , js requires 2 object parameters done in previous version this:

db database = mongoclient.getdb(db); commandresult cr = database.doeval(js, query, collection); // js string, query basicdbobject , collection list<string> 

need in running same in place of db getting mongodatabase (as getdb has been deprecated) , doeval replaced runcommand

you can in code of original doeval method figure out how this, looks like:

public commandresult doeval(final string code, final object... args) {     dbobject commanddocument = new basicdbobject("$eval", code).append("args", arrays.aslist(args));     return executecommand(wrap(commanddocument)); } 

that means you'll need like:

document commanddocument = new document("$eval", code).append("args", arrays.aslist(args)); return runcommand(commanddocument); 

note running scripts on server application code not recommended, you're better off translating java code, driver has more efficient support this.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -