Reputation: 21
I try run command mongo in linux console without entering into mongo shell. To do it:
[root@router-mongos ~]# mongo --eval " printjson(show databases)"
But not run, this is the output:
MongoDB shell version: 2.6.10 connecting to: test 2015-06-10T18:33:39.834+0200 SyntaxError: Unexpected identifier
Though if you are uses:
[root@router-mongos ~]# mongo maria --eval " printjson (db.stats())" o mongo --eval " printjson(db.adminCommand('listDatabases'))"
Yes, the output is the same if you run it in shell.
Has anyone ever used this? can we help me? Thanks.
Upvotes: 2
Views: 947
Reputation: 52030
From the Mongo Shell documentation:
You cannot use any shell helper (e.g.
use <dbname>
,show dbs
, etc.) inside the JavaScript file because they are not valid JavaScript.
Following that, there is a table showing the JavaScript equivalents of the various shell helpers. From that, show dbs
and show databases
should be replaced by db.adminCommand('listDatabases')
in your Mongo shell scripts.
Upvotes: 3