{"id":38825,"date":"2025-11-10T09:00:00","date_gmt":"2025-11-10T08:00:00","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=38825"},"modified":"2025-11-10T09:00:00","modified_gmt":"2025-11-10T08:00:00","slug":"setting-up-tls-encryption-and-authentication-in-mongodb","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/","title":{"rendered":"Setting up TLS encryption and authentication in MongoDB"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When <strong>securing a MongoDB deployment<\/strong>, protecting sensitive data is essential. MongoDB supports encryption <strong>throughout the lifecycle<\/strong> of the data, with three primary types of data encryption :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Encryption <strong>in transit<\/strong><\/li>\n\n\n\n<li>Encryption <strong>at rest<\/strong><\/li>\n\n\n\n<li>Encryption <strong>in use<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Among these, <strong>encryption in transit<\/strong> is fundamental : it protects data as it moves between your application and the database. In MongoDB, this is achieved through <strong>TLS (Transport Layer Security)<\/strong>, which ensures that communication remains private and secure. You have two options when it comes to using TLS for your database :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using TLS for <strong>encryption<\/strong> only.<\/li>\n\n\n\n<li>Using TLS both for <strong>encryption<\/strong> and <strong>authentication<\/strong> to the database.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 id=\"h-setting-up-tls-for-encryption\" class=\"wp-block-heading\">Setting up TLS for encryption<\/h2>\n\n\n\n<h3 id=\"h-create-a-certificate-authority\" class=\"wp-block-heading\">Create a certificate authority<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ll first create a <strong>Certificate Authority<\/strong>. These certificates will be self-signed, which is fine for testing, but <strong>you shouldn&#8217;t use self-signed certificates in a production environment !<\/strong> On Linux, use the <code>openssl<\/code> library to generate the certificates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -newkey rsa:4096 -nodes -x509 -days 365 -keyout ca.key -out ca.pem -subj \"\/C=CH\/ST=ZH\/L=Zurich\/O=dbi\/OU=MongoDBA\/CN=vm.domain.com\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a description of some important parameters of the commands :<\/p>\n\n\n\n<ul class=\"nv-cv-m wp-block-list\">\n<li><code>-newkey rsa:4096<\/code> : Generates a new private key and a certificate request using RSA with a 4096-bit key size.<\/li>\n\n\n\n<li><code>-nodes<\/code> : Skips password encryption of the private key. Without it, OpenSSL would prompt you to set a passphrase.<\/li>\n\n\n\n<li><code>-x509<\/code> : Generates a self-signed certificate. <code>x509<\/code> is supported by MongoDB.<\/li>\n\n\n\n<li><code>-days 365<\/code> : Validity of the certificate in days.<\/li>\n\n\n\n<li><code>-keyout ca.key<\/code> : Filename for the private key.<\/li>\n\n\n\n<li><code>-out ca.pem<\/code> : Filename for the certificate.<\/li>\n\n\n\n<li><code>-subj \"...\"<\/code> : Provides the subject&#8217;s Distinguished Name (DN). If you don&#8217;t specify it, OpenSSL will prompt for each field.<\/li>\n<\/ul>\n\n\n\n<h3 id=\"h-create-a-server-certificate\" class=\"wp-block-heading\">Create a server certificate<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Then, we&#8217;ll create the server certificate for the MongoDB instance. In the <code>openssl-server.cnf<\/code> file below, you should change the <code>req_distinguished_name<\/code> fields with what you used while creating the Certificate Authority, and replace <code>vm.domain.com<\/code> by the name of your machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you only have an IP and no DNS entry for your VM, use <code>IP.1<\/code> instead of <code>DNS.1<\/code> in the <code>alt_names<\/code> section.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &gt; openssl-server.cnf &lt;&lt;EOF\n&#091; req ]\ndistinguished_name = req_distinguished_name\nreq_extensions = v3_req\nprompt = no\n\n&#091; req_distinguished_name ]\nC = CH\nST = ZH\nL = Zurich\nO = dbi\nOU = MongoDBA\n<strong>CN = myVM\n<\/strong>\n&#091; v3_req ]\nkeyUsage = digitalSignature, keyEncipherment\nextendedKeyUsage = serverAuth\nsubjectAltName = @alt_names\n\n&#091; alt_names ]\n<strong>DNS.1 = myVM\n<\/strong>EOF<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then, generates the certificate with these commands :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -newkey rsa:4096 -nodes -keyout mongodb-server.key -out mongodb-server.csr -config openssl-server.cnf\n\nopenssl x509 -req -in mongodb-server.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out mongodb-server.crt -days 365 -extensions v3_req -extfile openssl-server.cnf\n\ncat mongodb-server.key mongodb-server.crt &gt; mongodb-server.pem<\/code><\/pre>\n\n\n\n<h3 id=\"h-create-a-client-certificate\" class=\"wp-block-heading\">Create a client certificate<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we&#8217;ll create a client certificate. The process is the same, with a few tweaks :<\/p>\n\n\n\n<ul class=\"nv-cv-m wp-block-list\">\n<li><code>OU<\/code> should be different from the one from the server certificate. It is not mandatory for the communication, but it will be for the authentication if you decide to enable it.<\/li>\n\n\n\n<li><code>CN<\/code> should also be different.<\/li>\n\n\n\n<li><code>extendedKeyUsage<\/code> should be set with <code>clientAuth<\/code> instead of <code>serverAuth<\/code>.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &gt; openssl-client.cnf &lt;&lt;EOF\n&#091; req ]\ndistinguished_name = req_distinguished_name\nreq_extensions = v3_req\nprompt = no\n\n&#091; req_distinguished_name ]\nC = CH\nST = ZH\nL = Zurich\nO = dbi\n<strong>OU = MongoDBAClient\nCN = userApp\n<\/strong>\n&#091; v3_req ]\nkeyUsage = digitalSignature, keyEncipherment\n<strong>extendedKeyUsage = clientAuth\n<\/strong>EOF<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The creation of the certificate is the same.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -newkey rsa:4096 -nodes -keyout mongodb-client.key -out mongodb-client.csr -config openssl-client.cnf\n\nopenssl x509 -req -in mongodb-client.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out mongodb-client.crt -days 365 -extensions v3_req -extfile openssl-client.cnf\n\ncat mongodb-client.key mongodb-client.crt &gt; mongodb-client.pem<\/code><\/pre>\n\n\n\n<h3 id=\"h-mongodb-configuration-change\" class=\"wp-block-heading\">MongoDB configuration change<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure to set permissions correctly for your certificates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 600 ca.pem mongodb-server.pem mongodb-client.pem\nchown mongod: ca.pem mongodb-server.pem mongodb-client.pem<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you can change your MongoDB configuration file to include the certificates. Simply add the <code>net.tls<\/code> part to your <code>mongod.conf<\/code> file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>net:\n  bindIp: yourIP\n  port: 27017\n  <strong>tls:\n    mode: requireTLS\n    certificateKeyFile: \/path\/to\/mongodb-server.pem\n    CAFile: \/path\/to\/ca.pem<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can now restart your MongoDB instance with <code>systemctl restart mongod<\/code> (or whatever you&#8217;re using), and then try the connection to your instance for your client. Of course, the port mentioned in the <code>net.port<\/code> field of your configuration file shouldn&#8217;t be blocked by your firewall.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; mongosh --host myVM --port 27017 --tls --tlsCertificateKeyFile mongodb-client.pem --tlsCAFile ca.pem\nCurrent Mongosh Log ID:\t682c9641bbe4593252ee7c8c\nConnecting to:\t\tmongodb:\/\/vmIP:27017\/?directConnection=true&amp;tls=true&amp;tlsCertificateKeyFile=client.pem&amp;tlsCAFile=ca.pem&amp;appName=mongosh+2.5.1\nUsing MongoDB:\t\t8.0.9\nUsing Mongosh:\t\t2.5.1\n\nFor mongosh info see: https:\/\/www.mongodb.com\/docs\/mongodb-shell\/\n\ntest&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;re now connected to your MongoDB instance through TLS ! And if you&#8217;re not using the certificate, the <code>requireTLS<\/code> mode prevents the connection from being established, and generated these error messages in your logs :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"t\":{\"$date\":\"2025-05-21T04:43:55.277+00:00\"},\"s\":\"I\",  \"c\":\"EXECUTOR\", \"id\":22988,   \"ctx\":\"conn52\",\"msg\":\"Error receiving request from client. Ending connection from remote\",\"attr\":{\"error\":{\"code\":141,\"codeName\":\"SSLHandshakeFailed\",\"errmsg\":\"<strong>The server is configured to only allow SSL connections<\/strong>\"},\"remote\":\"IP:50100\",\"connectionId\":52}}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>If you want to learn more about MongoDB logs, I wrote a blog on this topic: <a href=\"https:\/\/www.dbi-services.com\/blog\/mongodb-log-analysis-a-comprehensive-guide\/\">MongoDB Log Analysis : A Comprehensive Guide<\/a>.<\/em><\/p>\n\n\n\n<h2 id=\"h-setting-up-tls-authentication\" class=\"wp-block-heading\">Setting up TLS authentication<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you&#8217;re connected, we will set up authentication so that you can be connected as a specific user to MongoDB. Using the already established connection, create a user in the <code>$external<\/code> database. Each client certificate that you create can be mapped to one MongoDB user. Retrieve the username that you will use :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; openssl x509 -in mongodb-client.pem -inform PEM -subject -nameopt RFC2253 | grep subject\nsubject=<strong>CN=userApp,OU=MongoDBA,O=dbi,L=Zurich,ST=ZH,C=CH<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And then create the user in the <code>$external<\/code> database, using the existing MongoDB connection :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test&gt; db.getSiblingDB(\"$external\").runCommand({\n  createUser: \"<strong>CN=userApp,OU=MongoDBA,O=dbi,L=Zurich,ST=ZH,C=CH<\/strong>\",\n  roles: &#091;\n    { role: \"userAdminAnyDatabase\", db: \"admin\" }\n  ]\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To check that everything works as intended, you can try to display collections in the <code>admin<\/code> database. For the moment, there is no error because you have all the rights to do it (no authorization is enforced).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test&gt; use admin\nswitched to db admin\nadmin&gt; show collections;\nsystem.users\nsystem.version<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can now edit the MongoDB configuration file by adding the <code>net.tls.allowConnectionsWithoutCertificates<\/code> set to <code>true<\/code>, and the <code>security.authorization<\/code> flag set to <code>enabled<\/code>. The <code>mongod.conf<\/code> file should look like this :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>net:\n  bindIp: X.X.X.X\n  port: XXXXX\n  tls:\n    mode: requireTLS\n    certificateKeyFile: \/path\/to\/mongodb-server.pem\n    CAFile: \/path\/to\/ca.pem\n<strong>    allowConnectionsWithoutCertificates: false\n<\/strong>\n<strong>security:\n  authorization: enabled<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After restarting with <code>systemctl restart mongod<\/code>, you can now connect again. If you use the same command as before, you will log in without authentication, and get the error below whenever you try to do anything :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MongoServerError&#091;Unauthorized]: Command listCollections requires authentication<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So you should now connect via this command :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mongosh --host vmIP --port 27017 --tls --tlsCertificateKeyFile mongodb-client.pem --tlsCAFile ca.pem --authenticationDatabase '$external' --authenticationMechanism MONGODB-X509<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to show the <code>admin<\/code> collections, you will now get an error, because your user only has the <code>userAdminAnyDatabase<\/code> role granted (this role was chosen during the user creation, see above).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>admin&gt; show collections\nMongoServerError&#091;Unauthorized]: not authorized on admin to execute command { listCollections: 1, filter: {}, cursor: {}, nameOnly: true, authorizedCollections: false, lsid: { id: UUID(\"9c48b4c4-7702-49ce-a97c-52763b2ad6b3\") }, $db: \"admin\" }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But it&#8217;s fine, you can grant yourself more roles (<code>readWriteAnyDatabase<\/code>, for instance) and create new users if you want.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>communication between the client and the server is now fully secured<\/strong>. Congratulations !<\/p>\n\n\n\n<h4 id=\"h-mongoservererror-badvalue\" class=\"wp-block-heading\">MongoServerError[BadValue]<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Side note<\/em> : if you ever encounter this error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MongoServerError&#091;BadValue]: Cannot create an x.509 user with a subjectname that would be recognized as an internal cluster member<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&#8230; make sure to follow the <a href=\"https:\/\/www.ietf.org\/rfc\/rfc2253.txt RFC-2253\">RFC-2253<\/a> standards. For instance, you could have this error if one of the field is too long. Also, as a reminder, the client certificate should have a different Distinguished Name (DN) than the server certificate (see <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/core\/security-x.509\/\">documentation<\/a> for more information).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When securing a MongoDB deployment, protecting sensitive data is essential. MongoDB supports encryption throughout the lifecycle of the data, with three primary types of data encryption : Among these, encryption in transit is fundamental : it protects data as it moves between your application and the database. In MongoDB, this is achieved through TLS (Transport&hellip;&nbsp;<\/p>\n","protected":false},"author":152,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","neve_meta_reading_time":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[4133,3788,1739],"tags":[995,1228,447,3690,1153,2211],"class_list":["post-38825","post","type-post","status-publish","format-standard","category-database","category-mongodb","category-nosql","tag-authentication","tag-authorization","tag-encryption","tag-mongoservererror","tag-openssl","tag-tls"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Setting up TLS encryption and authentication in MongoDB - dbi services Blog<\/title>\n<meta name=\"description\" content=\"Guiding you through setting up TLS encryption and authentication in any recent version of MongoDB, to secure connections between your database and your application.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting up TLS encryption and authentication in MongoDB\" \/>\n<meta property=\"og:description\" content=\"Guiding you through setting up TLS encryption and authentication in any recent version of MongoDB, to secure connections between your database and your application.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi services Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/dbiservices\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-10T08:00:00+00:00\" \/>\n<meta name=\"author\" content=\"Julien Delattre\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:site\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Julien Delattre\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/setting-up-tls-encryption-and-authentication-in-mongodb\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/setting-up-tls-encryption-and-authentication-in-mongodb\\\/\"},\"author\":{\"name\":\"Julien Delattre\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/0e990b04385bd7ff84b414bb8d92c544\"},\"headline\":\"Setting up TLS encryption and authentication in MongoDB\",\"datePublished\":\"2025-11-10T08:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/setting-up-tls-encryption-and-authentication-in-mongodb\\\/\"},\"wordCount\":794,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"keywords\":[\"Authentication\",\"Authorization\",\"encryption\",\"mongoservererror\",\"OpenSSL\",\"TLS\"],\"articleSection\":[\"Database\",\"MongoDB\",\"NoSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/setting-up-tls-encryption-and-authentication-in-mongodb\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/setting-up-tls-encryption-and-authentication-in-mongodb\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/setting-up-tls-encryption-and-authentication-in-mongodb\\\/\",\"name\":\"Setting up TLS encryption and authentication in MongoDB - dbi services Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"datePublished\":\"2025-11-10T08:00:00+00:00\",\"description\":\"Guiding you through setting up TLS encryption and authentication in any recent version of MongoDB, to secure connections between your database and your application.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/setting-up-tls-encryption-and-authentication-in-mongodb\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/setting-up-tls-encryption-and-authentication-in-mongodb\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/setting-up-tls-encryption-and-authentication-in-mongodb\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting up TLS encryption and authentication in MongoDB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi services Blog\",\"description\":\"#BeSharing\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\",\"name\":\"dbi services\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"width\":512,\"height\":512,\"caption\":\"dbi services\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/dbiservices\\\/\",\"https:\\\/\\\/x.com\\\/dbiservices\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/dbi-services\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/dbiservices\"],\"description\":\"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.\",\"email\":\"info@dbi-services.com\",\"telephone\":\"+41 32 422 96 00\",\"legalName\":\"dbi services SA\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/0e990b04385bd7ff84b414bb8d92c544\",\"name\":\"Julien Delattre\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/JDE_Web-1-scaled.jpg\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/JDE_Web-1-scaled.jpg\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/JDE_Web-1-scaled.jpg\",\"caption\":\"Julien Delattre\"},\"description\":\"Julien Delattre, member of the Oracle Team Zurich, has more than five years of experience specializing in Oracle databases, plus expertise in MariaDB and MongoDB. Prior to dbi services, he was a Database Administrator at Atos in Angers, France, and a Data Scientist at Air France in Paris and Apurata in Lima. Julien holds a Master's degree in Computer Science, Data Science, and Statistics from Centrale Paris \\\/ Universit\u00e9 Paris-Saclay.\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/julien-delattre\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Setting up TLS encryption and authentication in MongoDB - dbi services Blog","description":"Guiding you through setting up TLS encryption and authentication in any recent version of MongoDB, to secure connections between your database and your application.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/","og_locale":"en_US","og_type":"article","og_title":"Setting up TLS encryption and authentication in MongoDB","og_description":"Guiding you through setting up TLS encryption and authentication in any recent version of MongoDB, to secure connections between your database and your application.","og_url":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/","og_site_name":"dbi services Blog","article_publisher":"https:\/\/www.facebook.com\/dbiservices\/","article_published_time":"2025-11-10T08:00:00+00:00","author":"Julien Delattre","twitter_card":"summary_large_image","twitter_creator":"@dbiservices","twitter_site":"@dbiservices","twitter_misc":{"Written by":"Julien Delattre","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/"},"author":{"name":"Julien Delattre","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0e990b04385bd7ff84b414bb8d92c544"},"headline":"Setting up TLS encryption and authentication in MongoDB","datePublished":"2025-11-10T08:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/"},"wordCount":794,"commentCount":0,"publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"keywords":["Authentication","Authorization","encryption","mongoservererror","OpenSSL","TLS"],"articleSection":["Database","MongoDB","NoSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/","url":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/","name":"Setting up TLS encryption and authentication in MongoDB - dbi services Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2025-11-10T08:00:00+00:00","description":"Guiding you through setting up TLS encryption and authentication in any recent version of MongoDB, to secure connections between your database and your application.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-tls-encryption-and-authentication-in-mongodb\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Setting up TLS encryption and authentication in MongoDB"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi services Blog","description":"#BeSharing","publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.dbi-services.com\/#organization","name":"dbi services","url":"https:\/\/www.dbi-services.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","width":512,"height":512,"caption":"dbi services"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/dbiservices\/","https:\/\/x.com\/dbiservices","https:\/\/www.linkedin.com\/company\/dbi-services\/","https:\/\/www.youtube.com\/user\/dbiservices"],"description":"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.","email":"info@dbi-services.com","telephone":"+41 32 422 96 00","legalName":"dbi services SA"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0e990b04385bd7ff84b414bb8d92c544","name":"Julien Delattre","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2025\/05\/JDE_Web-1-scaled.jpg","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2025\/05\/JDE_Web-1-scaled.jpg","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2025\/05\/JDE_Web-1-scaled.jpg","caption":"Julien Delattre"},"description":"Julien Delattre, member of the Oracle Team Zurich, has more than five years of experience specializing in Oracle databases, plus expertise in MariaDB and MongoDB. Prior to dbi services, he was a Database Administrator at Atos in Angers, France, and a Data Scientist at Air France in Paris and Apurata in Lima. Julien holds a Master's degree in Computer Science, Data Science, and Statistics from Centrale Paris \/ Universit\u00e9 Paris-Saclay.","url":"https:\/\/www.dbi-services.com\/blog\/author\/julien-delattre\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/38825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/152"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=38825"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/38825\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=38825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=38825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=38825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}