Pass a .js file to mongo db.eval()

匿名 (未验证) 提交于 2019-12-03 09:21:58

问题:

I am trying to get variety working with db.eval() instead of commandline --eval. This is because I get some problems with authentication.

The normal use is from the commandline:

$ mongo test --eval "var collection = 'users', maxDepth = 3" /path/to/variety.js

What I am trying to do is this:

$ mongo >> use admin >> db.auth("foo", "bar") >> use anotherColl >> db.eval("/path/to/variety.js", "var collection = 'users', maxDepth = 3") >> Thu Mar  7 13:19:10 uncaught exception: {     "errmsg" : "compile failed: JS Error: SyntaxError: invalid flag after regular expression nofile_a:0",     "ok" : 0 }

Is there a way to have db.eval() eat an javascript file instead of an string?

回答1:

According to @Sammaye and my gut feeling you can't put in .js files in db.eval(). However for variety there is an solution described here.

mongo -u USER-p PASS admin --eval "var collection = 'COL', db_name='DB_NAME'" variety.js

And now the authentication problem :(



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!