We have a User doc in Mongo DB and want to use the _id field as the userID field and increment it.
i found a counter("user") JS method in Mongo docs (http://www.mongodb.org/display/DOCS/Object+IDs).
From the Mongo Shell, i can invoke,
db.user.insert({_id:counter("user"), name:"tom"...});
Now, how can i use the same command from Java code? Not able to find a way to specify the Javascript function from Java code.
Also saw the findAndModify Command and usage of $inc, but not able to get it to work. This way we can do without invoking the JS counter func, i presume.
What are the implications of using custom value in the _id field instead of the Mongo's Object Id, any caveats?
~vish