I like to run the equvilant of mongodb shell script from java
Mongo shell script is :
db.users.insert(
{
_id: getNextSequence("userid"),
name: "Sarah C."
}
)
I've tried something like this in java, which did not work .
BasicDBObject krUserRecord = new BasicDBObject("_id", getNextSequence("userid"))
.append("name", "Sarah C");
Can anyone help ?
getNextSequenceis a function written in themongojavascript shell. Neither the database (mongod) nor the Java side knows this function exists and neither is able to interprete the Javascript code the function contains. You will have to reimplement it in Java.