MongoDB functions with print to console


I have been very pleased with the DataGrip interface to MongoDB. I plan to use it for my Irtro to Database systems class.

I have found a problem I can't seem to resolve. 

The following code snippet assigns a mongodb cursor to a variable and then attempts to loop through print pieces to the console.

The code executes successfully (no errors), but there is no console display. Is there a setting or missing console window that I haven't exposed to make this work. In the Mongodb shell it works as expected, displaying the fields from the matching documents.

var cursor1 = db.course.find();
cursor1.forEach(function(x) { print(x.courseCd); });

if I enter cursor1 and execute it, it does display the correct items in the cursor.
So I am pretty certain it is the display that is not working.


Roland DePratti

Univ of Richmond

1 comment
Comment actions Permalink
Official comment

Hello Rdepratt,
You are right, print function is currently now supported in DataGrip.
DataGrip displays value of evaluated statement. forEach function does not return result therefore you don't see anything.

A workaround is to append values to a list and then evaluate the list:

var cursor1 = db.course.find();
var arr = [];
cursor1.forEach(function(x) { arr.push(x.courseCd); });


It's possible to implement print function. I'll try to fix this problem next week. Once it's fixed you'll need to only update driver, no need to wait for IDE update.
Here is an issue for this:

Please sign in to leave a comment.