我正在使用 JavaScript 从 mongo
shell 一次连接到多个数据库。但是,我的一个数据库在 Digital Ocean 而不是 AWS 上,所以我的 EC2 服务器上有一个 SSL 证书。
一般来说,我使用类似这样的东西在一个文件上连接和使用多个服务器:
var iptDb = connect("###.###.###.###:27017/dbname);
iptDb.auth("username", cat("pw"));
为了连接到我的 Digital Ocean 数据库,我知道我需要添加 ?ssl=true,如下所示,但我不知道我将证书信息放在哪里。
var iptDb = connect("###.###.###.###:27017/dbname?ssl=true");
iptDb.auth("username", cat("pw"));
mongo
uses --sslCAFile in the shell to give the certificate path.What would be the equivalent if I want to write it in my JavaScript file?
有关 --sslCAFile
的更多信息,请访问 MongoDB Configure SSL
最佳答案
mongo
shell 并不是要完全替代驱动程序;某些选项(如 --sslCAFile
)只能作为命令行参数提供。与 MongoDB 3.2 一样,mongo
shell 脚本还有其他限制,例如 I/O 选项很少(没有输入方法和有限的输出方法)。
如果您的要求相对简单并且您不想安装驱动程序,您可以编写一个 shell 脚本 (bash/zsh/...) 来运行 mongod
的多个调用预期的连接参数。
对于任何重要的脚本,我建议使用 officially supported drivers 之一这将包括对 SSL 选项的完全支持。例如,请参阅 Node.js driver SSL connection tutorial .
关于javascript - mongo shell JavaScript 相当于 --sslCAFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37737705/