【问题标题】:bad auth : Authentication failedbad auth:身份验证失败
【发布时间】:2021-11-03 06:20:54
【问题描述】:

我是 MERN 堆栈的新手,遇到了这个错误。

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
bad auth : Authentication failed.

这是我的代码,我尝试更改密码,但无济于事

import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import cors from "cors";

const app = express();

app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());

const CONNETCION_URL =
  "mongodb+srv://myratcharyyev:<password>@cluster0.mn9xi.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
const PORT = process.env.PORT || 5000;

mongoose
  .connect(CONNETCION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
  .then(() =>
    app.listen([PORT, () => console.log(`Server running on port : ${PORT}`)])
  )
  .catch((error) => console.log(error.message));

// mongoose.set("useFindAndModify", false);

【问题讨论】:

  • 您是否在 Mongo Atlas 设置中开放了从任何地方访问(IP 白名单)?
  • 是的,还是同样的错误。

标签: node.js reactjs mongoose mern nodemon


【解决方案1】:
const CONNETCION_URL =
  "mongodb+srv://myratcharyyev:<password>@cluster0.mn9xi.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
const PORT = process.env.PORT || 5000;

在 CONNETCION_URL 中,您是否在运行代码时将 &lt;password&gt; 更改为您在 mongodb 站点上设置的代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 2021-09-06
    • 2014-05-22
    • 2012-10-21
    • 2014-01-24
    相关资源
    最近更新 更多