0

I created a user in MongoDB using

db.createUser({user:"admin", pwd:"admin", role : [{role:"readWrite", db:"someDB"}]});

But I assume this user has been created with the default authentication mechanism. So if I want to authenticate only using, lets say SRAM-SHA-256, I tried doing

db.createUser({user: "test", pwd:"test", role:[{role:"readWrite", db}], mechanisms: [ "SCRAM-SHA-256" ]})

But this doesn't seem to work. It is throwing an error

Error: couldn't add user: "mechanisms" is not a valid argument to createUser

How to do this ? I am using MongoDB version 3.6.18

Jackson
  • 91
  • 1
  • 2
  • 6

1 Answers1

1

You are getting the error because MongoDB version 3.6 doesn't support the mechanisms argument for db.createUser() function, you can check that in MongoDB 3.6 Doc

And also the mechanism SCRAM-SHA-256 you are trying to implement doesn't work in MongoDB 3.6, it was introduced in MongoDB 4.0, you can check that on SCRAM-SHA-1 and SCRAM-SHA-256 DOC

And as written in the latest MongoDB Docs, by default in 3.6 it's SCRAM-SHA-1 and you can't change it.

mechanisms - The default for featureCompatibilityVersion is 3.6 is SCRAM-SHA-1

Puneet Singh
  • 3,477
  • 1
  • 26
  • 39