I'm following this fullstack course but I'm not able to connect to my mongoDB Atlas database.
I have had a whitelist entry that allows access from anywhere as per the tutorial since the beginning and I'm certain my username is ok in the url (it is Database Acces one, etc.) so I don't think that's the issue.
I tried the code below (node, using mongoose) and it didn't work. I tried the official mongoDB node.js library and it also didn't work (also connection timeOut). I even installed MongoCompass and got a connection timeout.
I did some research and it seems like the issue is my firewall blocks access to 27017, as suggested here, and I tried the and at first it didn't work at all (the page never loaded). I temporarily disabled my ufw to try and now it sort of works: the page loads at the beginning, but it keeps "loading" (even if I can see the content) and after a while it disappears.
I wonder if I should give it access to iptables as suggested here the IP address of my application and I'm very lost here. So my question is how to do that?
const mongoose = require('mongoose')
const url = "/* here i put my url with the appropiate username, password, database name, etc.*/"
mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false, useCreateIndex: true })
const noteSchema = new mongoose.Schema({ content: String, date: Date, important: Boolean
})
const Note = mongoose.model('Note', noteSchema)
const note = new Note({ content: 'HTML is Easy', date: new Date(), important: true
})
note.save().then(result => { console.log('note saved!') mongoose.connection.close()
})This is the error I get when I run that file:
/home/julia/test-rep/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:184 callback(new MongooseError(message)); ^
MongooseError: Operation `notes.insertOne()` buffering timed out after 10000ms at Timeout.<anonymous> (/home/julia/test-rep/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:184:20) at listOnTimeout (node:internal/timers:556:17) at processTimers (node:internal/timers:499:7)I've gotten this error with MongoClient:
MongoServerSelectionError: connection timed out at Timeout._onTimeout (/home/julia/node_modules/mongodb/lib/core/sdam/topology.js:438:30) at listOnTimeout (node:internal/timers:556:17) at processTimers (node:internal/timers:499:7)as well as this error when going into more detail:
MongoServerSelectionError: connection timed out at Timeout._onTimeout (/home/julia/node_modules/mongodb/lib/core/sdam/topology.js:438:30) at listOnTimeout (node:internal/timers:556:17) at processTimers (node:internal/timers:499:7) { reason: TopologyDescription { type: 'ReplicaSetNoPrimary', setName: 'atlas-z3fex8-shard-0', maxSetVersion: null, maxElectionId: null, servers: Map(3) { '/*name of my*/cluster-shard-00-00.9a0bz.mongodb.net:27017' => [ServerDescription], '/*name of my*/cluster-shard-00-02.9a0bz.mongodb.net:27017' => [ServerDescription], '/*name of my*/cluster-shard-00-01.9a0bz.mongodb.net:27017' => [ServerDescription] }, stale: false, compatible: true, compatibilityError: null, logicalSessionTimeoutMinutes: 30, heartbeatFrequencyMS: 10000, localThresholdMS: 15, commonWireVersion: 8 }
}I would really appreciate any help!
Reset to default