コンテンツにスキップ

MongoDBへダンプデータを追加

データの追加にはmongoimportコマンドを使う.

mongoimport --host="127.0.0.1" --port=27017 --db="paper" --collection="paper" --type="json" --file="paper.json" --username=root --password=example --authenticationDatabase admin

実行結果:

2022-06-06T12:48:25.294+0000    connected to: mongodb://127.0.0.1:27017/
2022-06-06T12:48:25.301+0000    95 document(s) imported successfully. 0 document(s) failed to import.

authenticationDatabaseオプションがないと下記のエラーが出るため,付ける必要がある.

2022-06-06T12:47:44.162+0000    error connecting to host: could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

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. のエラーでた | ITや技術やテクノロジーにアンテナはってみた