arrays - MongoDB commands in linux console with --eval (print -


i try run command mongo in linux console without entering mongo shell. it:

[root@router-mongos ~]# mongo --eval " printjson(show databases)"

but not run, output:

mongodb shell version: 2.6.10 connecting to: test 2015-06-10t18:33:39.834+0200 syntaxerror: unexpected identifier

though if uses:

[root@router-mongos ~]# mongo maria --eval " printjson (db.stats())" o mongo --eval " printjson(db.admincommand('listdatabases'))"

yes, output same if run in shell.

has ever used this? can me? thanks.

from mongo shell documentation:

you cannot use shell helper (e.g. use , show dbs, etc.) inside javascript file because not valid javascript.

following that, there table showing javascript equivalents of various shell helpers. that, show dbs , show databases should replaced db.admincommand('listdatabases') in mongo shell scripts.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -