Search code examples
mongodb-java

Save a javascript code as store function via Java API


I want to save a javascript code as store function via Java API. The problem is that I don't know how to convert String (type 2) to code (type 13). I know that in PHP it's possible:

new mongo.Code("function myFunction() { return 123; }").

So is there any way to save stored function via Java API?


Solution

  • It's very similar in Java:

    final Code code = new Code("function myFunction() { return 123; }");