I am trying to connect to AWS Document DB (MongoDB) in rails using "mongoid" gem (7.5.1) which internally uses mongo gem (2.18)
dev:
clients:
default:
database: my_database_name
hosts:
- docdb.dev.mysite.internal:27017
options:
read:
mode: :primary
auth_mech: :aws
max_pool_size: 1
I followed the documentation for both mongoid and mongo gem and they have mandated to use auth_mechanism as "aws" when we want to provide authentication credentials using AWS IAM. With the above config/mongoid.yml , when I try to connect , getting below error
User (mechanism: aws) is not authorized to access my_database_name (auth source: $external, used mechanism: MONGODB-AWS, used server: docdb.dev.mysite.internal:27017 (PRIMARY)): [73]:
Invalid character $ in database name: $external (modern retry, attempt 1) (Mongo::Auth::Unauthorized)
Seems like when auth_mech is set to aws
, mongo gem sets the auth_source as $external. Based on the documentation here https://www.mongodb.com/docs/ruby-driver/current/reference/authentication/#authentication-mechanisms
, auth source is the database where users authentication credentials are stored.
Please suggest the way to make it work.