简体   繁体   English

mongo shell JavaScript等效于--sslCAFile

[英]mongo shell JavaScript equivalent to --sslCAFile

I'm using JavaScript to connect to multiple databases at once from the mongo shell. 我正在使用JavaScript从mongo shell一次连接到多个数据库。 However, one of my databases is on Digital Ocean instead of AWS so I have an SSL certificate on my EC2 server. 但是,我的一个数据库位于Digital Ocean而不是AWS上,因此我的EC2服务器上具有SSL证书。

In general, I use something similar to this to connect and use multiple servers on one file: 通常,我使用与此类似的方法在一个文件上连接和使用多个服务器:

var iptDb = connect("###.###.###.###:27017/dbname);
iptDb.auth("username", cat("pw"));

In order to connect to my Digital Ocean database, I know that I need to add ?ssl=true , like below, but I don't know where I put the certificate information. 为了连接到我的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. mongo在外壳程序中使用--sslCAFile提供证书路径。

What would be the equivalent if I want to write it in my JavaScript file? 如果我想将其写入JavaScript文件,那将是什么意思?

More information on --sslCAFile at MongoDB Configure SSL 有关MongoDB--sslCAFile更多信息配置SSL

The mongo shell isn't intended to be a full driver replacement; mongo shell不能完全替代驱动程序; some options (like --sslCAFile ) can only be provided as command line parameters. 某些选项(例如--sslCAFile )只能作为命令行参数提供。 As at MongoDB 3.2 there are other limitations of mongo shell scripts such as few I/O options (no input methods and limited output methods). 从MongoDB 3.2开始, mongo shell脚本还有其他限制,例如很少的I / O选项(无输入法和有限的输出法)。

If your requirements are relatively straightforward and you don't want to install a driver, you could perhaps write a shell script (bash/zsh/...) to run multiple invocations of mongod with the expected connection parameters. 如果您的要求相对简单,并且不想安装驱动程序,则可以编写一个shell脚本(bash / zsh / ...)以运行带有预期连接参数的mongod多次调用。

For any significant scripting I would recommend using one of the officially supported drivers which will include full support for SSL options. 对于任何重要的脚本,我建议使用一种官方支持的驱动程序 ,其中包括对SSL选项的全面支持。 For example, see the Node.js driver SSL connection tutorial . 例如,请参阅Node.js驱动程序SSL连接教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM