Ananth
(Ananth)
September 27, 2022, 5:13pm
1
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 {
console.log('Connected')
}
});
.....
};
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!
Jack_Woehr
(Jack Woehr)
September 27, 2022, 7:14pm
2
Is the Postgresql instance set up for TLS?
Ananth
(Ananth)
September 28, 2022, 5:27am
3
Yes, we are using Azure PostgreSQL server and it is setup with TLS. Here is a reference to the relevant documentation.
Jack_Woehr
(Jack Woehr)
September 28, 2022, 11:28am
4
Ananth
(Ananth)
September 28, 2022, 1:55pm
5
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.
Thanks!
Jack_Woehr
(Jack Woehr)
September 28, 2022, 3:19pm
6
@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?
Ananth
(Ananth)
September 28, 2022, 5:53pm
7
@Jack_Woehr
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) โ
โโโโโโโโโโโโโโโโโ
Jack_Woehr
(Jack Woehr)
September 28, 2022, 6:36pm
8
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.
Ananth
(Ananth)
September 29, 2022, 6:22am
9
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
Hi,
I have the same problem. Have you find the solution?
Thanks in advance for your reply.
Ananth
(Ananth)
December 19, 2022, 4:37am
11
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โ