Connecting to PostgreSQL from MongoDB Atlas trigger

Hello All,

We are trying to push selective data from Atlas DB to PostgreSQL database using triggers. Below is the snippet of code used to connect to PostgreSQL.

exports = function(changeEvent) {
  const { Client } = require('pg')
  const client = new Client({
    host: 'xxxxx',
    port: xxx,
    dbname: 'xxxxxxx',
    user: 'xxxxxxx',
    password: 'xxxxxxx',
    ssl: true,
  client.connect(err => {
	if (err) {
	  console.error('Connection error', err)
	} else {

As seen above, node-postgres is being used to connect to the database. While this code works fine when executed through a standalone program, we are getting the below TLS error from MongoDB trigger function.

> error logs: 
connection error FunctionError: 'tls' module: not a TLS connection

Appreciate any help to resolve this issue. Thanks!

Is the Postgresql instance set up for TLS?

Yes, we are using Azure PostgreSQL server and it is setup with TLS. Here is a reference to the relevant documentation.

Have you carefully read and ?

Hi Jack_Woehr,

Yes, have gone through those and checked them again, but couldn’t find any related information. Please let me know if I’m missing something.


@Ananth is this the setup that works?

[Atlas cloud]  --->  [Postgresql somewhere]
[Your workstation running a standalone program]

or with the standalone program do you fetch the data from Atlas to your workstation and then from your workstation write it to Postgresql?


To validate the PostgreSQL SSL setup, I’ve tried the below mode and it works fine.

│ node.js standalone │
│ program from local │
│       machine      │
 	      │ Connects over 
	      │ SSL successfully
    │ PostgreSQL│

What we intend to do is below, which is not working:

│  MongoDB  │
│   Atlas   │
	  │    Push using
	  │     triggers 
	  │(fails with TLS error)
│  PostgreSQL  │
│(same instance│
│ as above)    │

Sounds like the outgoing connection from Atlas is blocked in some fashion.
Are you a paying Atlas customer? If so, file a support ticket. The menu is in the upper right of the Atlas web interface.
If you’re on the free plan, I suspect that sort of triggered callout to a 3rd-party site may not be supported.
I’m not a MongoDB employee, but I think it’s a question Atlas support will have to answer for you.

I had the same doubt and had tried connecting to an external service over HTTPS, that works fine.
We will explore reaching out to Atlas Support.

Thanks very much for your time!

1 Like


I have the same problem. Have you find the solution?

Thanks in advance for your reply.

No, we were not able to resolve this and hence moved the sync logic to our application code.

Hi Folks – What version of the pg npm package are you using? We do test with v8.7.1 and the hope is that is supported.

I am also trying to connect to a remote Postgres DB from Atlas trigger. I downgraded pg npm package to 8.7.1 but still having the same error:

Connection error FunctionError: ‘tls’ module: not a TLS connection

Hi, what is the version of your Postgres DB server?

I am using Postgres 11.18

It should work now. Please check it out.

We are trying something similar. We tried to connect to MSSQL, but the mssql dependency couldnt be added in atlas function, the dependency resolution failed with some package named js-joda. Later we tried connecting to ftp using ftp package and ran into the same issue “‘tls’ module: not a TLS connection”