mongodbにデータ一括インサートで error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed. のエラーでた mongodb

新しく環境構築しててmongodbにデータ一括インサートしようとすると
error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism SCRAM-SHA-1 : (AuthenticationFailed) Authentication failed.
のエラーがでた。

ナニコレ?
前の環境ではこんなんでたっけな?
それともversion新しくなって変わったのか?docker上でつくってるからなのか?

結論としては mongoimport コマンド使用時に、
ユーザ、
パスワード、
ユーザ管理者でMongoDBに接続する場合、--authenticationDatabase adminが必要らしい
ので上記を追加したら実行できたよ


■ mongodbにデータ一括投入NGパターン
・--authenticationDatabase admin をつけないと以下のエラーになる
# mongoimport --db hogedb --collection hogecollection --drop --file insert_hoge.json -u hogeuser -p hogepassword

2020-06-14T06:30:03.245+0000 error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism SCRAM-SHA-1 : (AuthenticationFailed) Authentication failed.



■ mongodbにデータ一括投入OKパターン
・user と password も指定するよ あと --authenticationDatabase admin もね
# mongoimport --db hogedb --collection hogecollection --drop --authenticationDatabase admin --file insert_hoge.json -u hogeuser -p hogepassword

2020-06-14T06:37:08.132+0000 connected to: mongodb://localhost/
2020-06-14T06:37:08.133+0000 dropping: hogedb.hogecollection
2020-06-14T06:37:08.901+0000 6238 document(s) imported successfully. 0 document(s) failed to import.