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
To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.
MongoDB logs can be found in the MongoDB log files at /var/log/mongodb/mongodb. log. If you can't find the log files from this location, you can check the mongodb. conf.
In MongoDB, you can use the show dbs command to list all databases on a MongoDB server. This will show you the database name, as well as the size of the database in gigabytes. You can select any database using the use statement and work on it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With