[英]Winston MongoDB - Authentication error when passing the database
我打開這個問題是因為我不確定這是否只發生在我身上。
在 mongo url 中傳遞數據庫時,我無法連接到數據庫。 我正在使用與此類似的結構:
const logger = winston.createLogger({
levels: customLevels,
format: winston.format.combine(
winston.format.errors({ stack: true }),
winston.format.json(),
winston.format.timestamp(),
),
transports: [
new winston.transports.MongoDB({
db: `mongodb://user:pass@host:port/database`,
tryReconnect: true,
collection: 'logs',
options: { useNewUrlParser: true, useUnifiedTopology: true }
}),
],
});
但是在嘗試連接時,出現以下錯誤:
winston-mongodb: will try reconnecting in 10 seconds
winston-mongodb: error initialising logger MongoError: Authentication failed.
當我從 mongodb 的連接字符串中刪除數據庫時,它會連接並在 mongo 上創建一個名為“test”的數據庫。 用戶名和密碼是正確的,因為我輸入了相同的數據來創建我嘗試連接的數據庫。
還有其他人正在經歷類似的事情嗎?
您很可能需要在您的 uri 中添加身份驗證數據庫,如下所示:
db: `mongodb://user:pass@host:port/database?authSource=admin`
否則 mongo 將在您提供的“數據庫”中搜索用戶...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.