我的 node 应用程序给了我这个消息

我已经在IP白名单上添加了我当前的IP地址和0.0.0.0.

下面是错误消息的图片和我为连接它而编写的代码.

var express = require('express');
var bodyparser = require('body-parser');
var mongoose = require('mongoose');

var app = express();
app.use(bodyparser.json());

mongoose
     .connect("mongodb+srv://<username:password>@my-cluster.mongodb.net/test?retryWrites=true&w=majority", 
     { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
     .then(() => console.log( 'Database Connected' ))
     .catch(err => console.log( err ));

    app.listen(3003)

这是我在运行nodemon后收到的错误.

[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
MongooseError [MongooseServerSelectionError]: Could not connect to any servers in your MongoDB Atlas cluster. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/.
    at new MongooseServerSelectionError (C:\Users\anna james\Dropbox\MERN_SHOPPING_LIST\back\node_modules\mongoose\lib\error\serverSelection.js:24:11)
    at NativeConnection.Connection.openUri (C:\Users\anna james\Dropbox\MERN_SHOPPING_LIST\back\node_modules\mongoose\lib\connection.js:823:32)
    at Mongoose.connect (C:\Users\anna james\Dropbox\MERN_SHOPPING_LIST\back\node_modules\mongoose\lib\index.js:333:15)
    at Object.<anonymous> (C:\Users\anna james\Dropbox\MERN_SHOPPING_LIST\back\server.js:9:7)
    at Module._compile (internal/modules/cjs/loader.js:1157:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
    at Module.load (internal/modules/cjs/loader.js:1001:32)
    at Function.Module._load (internal/modules/cjs/loader.js:900:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  message: "Could not connect to any servers in your MongoDB Atlas cluster. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/.",
  name: 'MongooseServerSelectionError',
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map {
      'cluster1-shard-00-01-m3rzz.mongodb.net:27017' => [ServerDescription],
      'cluster1-shard-00-02-m3rzz.mongodb.net:27017' => [ServerDescription],
      'cluster1-shard-00-00-m3rzz.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: null
  },
  [Symbol(mongoErrorContextSymbol)]: {}
}


Error Message and code

推荐答案

你在使用代理吗??请先try 不同的互联网连接.

Mongodb相关问答推荐

MongoDB即使在使用索引时也很慢

数组过滤器 MongoDB

如何在 MongoDB 中对字段进行自定义排序

如何将以下聚合查询转换为 bson 并在 golang 中执行

使用 $addFields 将字段添加到 $lookup 结果中的每个项目

MongoDB C# 驱动程序 - 如何将 _id 存储为 ObjectId 但映射到字符串 Id 属性?

MongoDB 使用自定义表达式或函数进行排序

如何在 MongoDb 中进行类似于嵌套 Sql Select 查询的嵌套查询

从性能Angular 来看 MongoDB 嵌入式与参考

NodeJS中的密码重置

MongoDB展开多个数组

Python - Pymongo 插入和更新文档

MongoDB - 文件大小巨大且不断增长

Mongoimport json 文件更新或覆盖..?

在 mongodb 中的索引列上查找重复项的快速方法

如何在 Rails 中混合使用 mongodb 和传统数据库?

mongoose 使用 $cond 中的 $exists 聚合

MongoDB打印两点之间的距离

如何使用户的邮箱在 mongoDB 中唯一?

我可以在 iOS 上使用 MongoDB 作为 CoreData 的替代品吗?