mongodbrobo3t

Log to console In Mongodb


When I run this command in robomongo, I get a output with different rows:

 db.getCollection('houses').find({})

Now I tried to run the same command in the mongo shell:

I wrote a script mongo.js:

  conn = new Mongo();
  db = conn.getDB("development");

  db.getCollection('houses').find({});

Opened the console with:

  mongo --shell

And tried to run the command:

  > load('mongo.js')
  true

I do not understand why I get only true as output. I want to see the query output! What do I wrong? Thanks


Solution

  • 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({}));