Unable to connect to Mongo DB using .js file

Hi All,

I am unable to connect to Mongo DB using .js file. Below is the string mentioned in .js file.

db = connect( ‘mongodb://user:pswd@db-1,db-a2,db-3/AlteryxGallery_Lucene?authSource=AlteryxGallery_Lucene&replicaSet=AlteryxProd&readPreference=primary --tlsCertificateKeyFile E:/bin/mongosh-1.10.6-win32-x64/bin/db-1.pem --tlsAllowInvalidCertificates’ );

I am getting below error while executing it as below in command line.

Loading file: Gallery.js
MongoInvalidArgumentError: Invalid read preference mode “primary --tlsCertificateKeyFile E:/bin/mongosh-1.10.6-win32-x64/bin/db-alteryx1.pem --tlsAllowInvalidCertificates”

Someone please help us.

You have mixed command line options --tlsCertificateKeyFile E:/bin/mongosh-1.10.6-win32-x64/bin/db-alteryx1.pem --tlsAllowInvalidCertificates with connection string uri format.

You will need to use the matching connection-string-options

Please use appropriate formatting to make posts more readable.

1 Like

Thanks Chris. I have used it as below with single and tried with double quotes of file location E:\bin\mongosh-1.10.6-win32-x64\bin\db-alteryx1.pem but throwing a different error. Please let me for any inputs.

db = connect( ‘mongodb://user:pswd@db-1,db-2,db-3/AlteryxGallery?authSource=AlteryxGallery&replicaSet=AlteryxProd&readPreference=primary&tls=true&tlsCertficateKeyFile=“E:\bin\mongosh-1.10.6-win32-x64\bin\db-alteryx1.pem”&tlsAllowInvalidCertificates=true’ );

Error :

MongoParseError: option tlscertficatekeyfile is not supported