Log to console In Mongodb
In the shell script, instead of console.log
you can use
print()
// for plain texts,
or printjson()
// for json
usage :
printjson(db.getCollection('houses').find({}));
When using
printjson(db.getCollection('houses').find({}));
I get the output from the find object.
{
"_mongo" : connection to ***.***.***.***,
"_db" : *****,
"_collection" : ***.houses,
"_ns" : "*****.houses",
"_query" : {
},
"_fields" : null,
"_limit" : 0,
"_skip" : 0,
"_batchSize" : 0,
"_options" : 4,
"_cursor" : null,
"_numReturned" : 0,
"_special" : false,
"help" : function () {
print("find(<predicate>, <projection>) modifiers")
print("\t.sort({...})")
...........
}
if you use
db.getCollection('houses').find({}).forEach(printjson)
I get the desired output.