steineey / node-red-contrib-mongodb4

MongoDB driver node for Node-RED
MIT License
26 stars 10 forks source link

MongoMissingCredentialsError: Username required for mechanism 'SCRAM-SHA-256' #29

Closed rcfmc closed 6 months ago

rcfmc commented 7 months ago

Hello,

I am having problems connecting to my mongo DB. This is how I am setting the node:

image

And I get an error message: MongoMissingCredentialsError: Username required for mechanism 'SCRAM-SHA-256'

However, from the same machine where I am running node-red, if I run mongosh with this command: mongosh "mongodb://dds-4xoa93a03aba11741.mongodb.germany.rds.aliyuncs.com:3717,dds-4xoa93a03aba11742.mongodb.germany.rds.aliyuncs.com:3717/clogging" --username nodered --password my_pasword

Then I can connect and create documents with no problems.

Any help on what I should be looking for? I have been trying different combinations in the configuration of my mongodb4-client without success.

Thanks

steineey commented 7 months ago

Hi, have you tried another auth mechanism apart from DEFAULT? In DEFAULT the driver is negotiating the mechanism, but if you can set an explicit mechanism I would do that. In my code I pass the credentials right to the mongo client instance.

You can also try this type of connection uri: mongodb:// @.***:27017 But keep in mind that this results in saving your credentials clear text in the credentials file. So use this only for testing.

You can also overwrite all MongoClient options with the JSON option including the authentication. Read the NodeJS MongoClient docs v5.9.2 to get a full overview whats possible.