2

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.