The following piece of code:
var mongo = require(\'mongodb\'); var db = new mongo.Db(\'test\', new mongo.Server(\'127.0.0.1\', 27017, {})); var callback
After reading the documentation about the driver data types, I realized that instead of passing the string with the code, I needed to pass a mongo.Code object:
{ "_id" : "myFunction", "value" : new mongo.Code("function myFunction() { return 123; }") }