将.js文件传递给mongo db.eval() [英] Pass a .js file to mongo db.eval()

查看:114
本文介绍了将.js文件传递给mongo db.eval()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使品种db.eval()而不是命令行--eval一起使用.这是因为我在身份验证方面遇到了一些问题.

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

我想做的是这个

$ 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
}

有没有办法让db.eval()吃一个javascript文件而不是一个字符串?

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

推荐答案

根据@Sammaye和我的直觉,您无法在db.eval()中放入.js文件.但是,对于多样性,在此处中介绍了一种解决方案.

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

现在是身份验证问题:(

这篇关于将.js文件传递给mongo db.eval()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆