Ausgabe
Meine Node-App gibt mir diese Meldung „Es konnte keine Verbindung zu Servern in Ihrem MongoDB-Atlas-Cluster hergestellt werden. Stellen Sie sicher, dass Ihre aktuelle IP-Adresse auf der IP-Whitelist Ihres Atlas-Clusters steht“.
Ich habe bereits meine aktuelle IP-Adresse zusammen mit der 0.0.0.0 auf der IP-Whitelist hinzugefügt.
Unten ist ein Bild der Fehlermeldung und des Codes, den ich geschrieben habe, um es zu verbinden. Ich bin neu bei node.js und mongodb. Ich habe alle Lösungen hier durchgesehen, aber keine davon konnte dies lösen.
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)
Dies ist der Fehler, den ich nach dem Ausführen von nodemon erhalte.
[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)]: {}
}
Lösung
Benutzt du einen Proxy?? Bitte versuchen Sie es zuerst mit einer anderen Internetverbindung.
Beantwortet von – Ali
Antwort geprüft von – Timothy Miller (FixError Admin)