Been trying to get past this challenge for over 6 hours using replit. Whenever I run my code in an attempt to establish connection with my MongoDB Atlas cluster, I get this annoying error:
MongooseServerSelectionError: Could not connect to any servers in your Mongodb Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted...(bla bla bla)
.
.
{
reason: TopologyDescription {
.....
.....
}
}
Meanwhile I already allowed access from anywhere on my mongodb cluster Newtwork Access.
Also when I submit my solution link I get the error below logged to my repl console:
MongooseError...
And here is the code in my myApp.js file:
require('dotenv').config();
var mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => console.log("Database connected"))
.catch(err => console.error(err));
const personSchema = new mongoose.Schema({
name: { type: String, required: true },
age: Number,
favoriteFoods: [String]
});
let Person = mongoose.model('Person', personSchema);
const createAndSavePerson = (done) => {
const person1 = new Person({
name: "Bankole Ayeni",
age: 22,
favoriteFoods: ["eba with gbegiri", "amala with ewedu"]
});
person1.save((err, data) => {
return err ? done(err) : done(null, data);
})
};
const createManyPeople = (arrayOfPeople, done) => {
done(null /*, data*/);
};
const findPeopleByName = (personName, done) => {
done(null /*, data*/);
};
const findOneByFood = (food, done) => {
done(null /*, data*/);
};
const findPersonById = (personId, done) => {
done(null /*, data*/);
};
const findEditThenSave = (personId, done) => {
const foodToAdd = "hamburger";
done(null /*, data*/);
};
const findAndUpdate = (personName, done) => {
const ageToSet = 20;
done(null /*, data*/);
};
const removeById = (personId, done) => {
done(null /*, data*/);
};
const removeManyPeople = (done) => {
const nameToRemove = "Mary";
done(null /*, data*/);
};
const queryChain = (done) => {
const foodToSearch = "burrito";
done(null /*, data*/);
};
/** **Well Done !!**
/* You completed these challenges, let's go celebrate !
*/
//----- **DO NOT EDIT BELOW THIS LINE** ----------------------------------
exports.PersonModel = Person;
exports.createAndSavePerson = createAndSavePerson;
exports.findPeopleByName = findPeopleByName;
exports.findOneByFood = findOneByFood;
exports.findPersonById = findPersonById;
exports.findEditThenSave = findEditThenSave;
exports.findAndUpdate = findAndUpdate;
exports.createManyPeople = createManyPeople;
exports.removeById = removeById;
exports.removeManyPeople = removeManyPeople;
exports.queryChain = queryChain;
My MONGO_URI in the Secrets(Environment variables) looks like this:
āmongodb://niranad:*****@solvexdb1.pivcw.mongodb.net/fccdb?retryWrites=true&w=majorityā
Here is a link to my repl:
I wonder if this challenge ever pass with replit?
Please help!
Thanks.