首页 > 解决方案 > 连接到 Mongodb 时出现错误

问题描述

这是我在脚本页面中编写的代码

常量猫鼬 = 要求(“猫鼬”);

mongoose.connect("mongodb://localhost:27017/userDB", {useNewUrlParser: true, useUnifiedTopology: true}, function(err){
  if(!err){console.log("Connected to Database");}
  else{console.log(err);}
});

const userSchema = {
  email: String,
  password: String
};

const User = new mongoose.model("User", userSchema);

////////////////错误显示在cmd/////////////////

reason:TopologyDescription {

            type: 'Single',
            setName: null,
            maxSetVersion: null,
            maxElectionId: null,
            servers: Map { 'localhost:27017' => [ServerDescription] },
            stale: false,
            compatible: true,
            compatibilityError: null,
            logicalSessionTimeoutMinutes: null,
            heartbeatFrequencyMS: 10000,
            localThresholdMS: 15,
            commonWireVersion: null
          }
        }

我在 2000 端口启动了我的本地主机。

当我尝试通过 Robo 3T 连接时,错误提示为 错误图像

标签: mongodbmongoose

解决方案


对于这种问题,我尝试了堆栈溢出和其他一些网站中可用的所有命令,最后我想出了一个解决方案,你必须mongodb正确重新安装并使用 CMD 删除所有与以下命令相关的文件夹mongodbmongoose然后npm uninstall mongodb --force重新npm uninstall mongoose --force启动你的服务器,你们都准备好了。不要忘记删除并重新安装与mongo项目文件夹中相关的所有文件。


推荐阅读