Console output on Mongo server on javascript server side

Has anyone understood the way to output to the console inside the javascript function that executes the server side in Mongo? Groovy below:

DBCollection js = db.getCollection('system.js') js.save([ '_id' : 'product', value : new Code(""" function(x,y) { alert('product called!'); // blows up... console.log('product called!'); // blows up... return x*y; } """ ) ]) js.eval('product(2,3)') 
+4
source share
1 answer

There are two functions that you can use to output from JavaScript that are displayed on the MongoDB server (including Map / Reduce functions):

  • print() - standard javascript print
  • printjson() - print as JSON

Both functions will output their output to the mongod and may be useful for debugging.

+10
source

All Articles