Printing
You can use the print method to print in the shell print('hello')
Iterating over a cursor
The value returned by find and findOne is not a collection but a 'cursor', so you can't just do
for(var obj in db.xyz.find())
you need to do
var cursor=db.xyz.find()
while(cursor.hasNext()) {
obj=cursor.next();
...
}
or define a function and use forEach()