코드
const mongoose = require('mongoose');
const MONGODB_URL = "mongodb+srv://name:<password>@생략";
mongoose.connect(MONGODB_URL, { useNewUrlParser: true, useUnifiedTopology: true }, err=>{
if(err){
console.log(err)
}
else{
console.log('success!');
}
});
오류 메세지
MongoError: bad auth : Authentication failed.
at MessageStream.messageHandler (/Users/user/Documents/node_modules/mongodb/lib/cmap/connection.js:268:20)
at MessageStream.emit (events.js:315:20)
at processIncomingData (/Users/user/Documents/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/Users/user/Documents/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at writeOrBuffer (internal/streams/writable.js:358:12)
at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at TLSSocket.ondata (internal/streams/readable.js:719:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
at TLSSocket.Readable.push (internal/streams/readable.js:223:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23) {
ok: 0,
code: 8000,
codeName: 'AtlasError'
}
MongoError: bad auth : Authentication failed.
너무나도 어이없는 오류로 <password> 에서 대괄호<>를 제거해 주어야함.
이 경우가 아니라면 비밀번호를 다시 확인하거나 접근 IP설정 했는지 확인해봐야함.