Connecting MongoDB to Ruby with Self-Signed Certificates for SSL

Given the popularity of our put up on connecting MongoDB SSL with Self-Signed Certificates in Node.js, we decided to write a tutorial on connecting MongoDB with Ruby. In this weblog, we’ll current you methods to be a part of to a MongoDB server configured with self-signed certificates for SSL using every the Ruby MongoDB driver and the favored Object-Document-Mapper (ODM) mongoid.

ScaleGrid at current makes use of self-signed certificates for SSL when creating nodes for a model new cluster. Additionally, we moreover current you with the selection of shopping for your private SSL certificates and configuring them on the MongoDB server, and you may e-mail help@scalegrid.io to be taught further about this present.

Connecting to a Replica Set Using Ruby MongoDB Driver

We will use the latest regular Ruby MongoDB driver mannequin 2.8 for this occasion. The 2.5.x variations of the driving force have a acknowledged bug that inhibit them from working with ScaleGrid deployments. The Ruby mannequin utilized in every the examples beneath is 2.6.3.

The connection decisions obtainable for the driving force are documented proper right here, and the alternatives we’ll need are:

:ssl
:ssl_verify
:ssl_ca_cert.

First, uncover and duplicate your MongoDB connection string from the cluster particulars internet web page on the ScaleGrid console:

The CA certificates file will also be obtainable for get hold of from the cluster particulars internet web page. Download and retailer the cert file at a location that is obtainable to the equipment:
Here’s a …

Read More on Datafloq