Hi all, I’m having problems completing this challenge and I’ve been stuck on it for a while.
I’ve gone through the installation guide for mongodb, and tried a few different things, but I don’t really know what the problem is. From the error message it seems like it’s not authorizing the access, but I don’t know why.
The ip address under network access is set to 0.0.0.0/0.
I tried changing the password for the database, but that didn’t help.
This is the error message the console on replit gives when I try to submit the link on fcc
npm start
> fcc-mongo-mongoose-challenges@0.0.1 start /home/runner/boilerplate-mongomongoose
> node server.js
(node:564) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Your app is listening on port 3000
GET
MongoError: user is not allowed to do action [insert] on [fcc-mongodb-and-mongoose.people]
at /home/runner/boilerplate-mongomongoose/node_modules/mongodb-core/lib/connection/pool.js:581:63
at authenticateStragglers (/home/runner/boilerplate-mongomongoose/node_modules/mongodb-core/lib/connection/pool.js:504:16)
at Connection.messageHandler (/home/runner/boilerplate-mongomongoose/node_modules/mongodb-core/lib/connection/pool.js:540:5)
at emitMessageHandler (/home/runner/boilerplate-mongomongoose/node_modules/mongodb-core/lib/connection/connection.js:310:10)
at TLSSocket.<anonymous> (/home/runner/boilerplate-mongomongoose/node_modules/mongodb-core/lib/connection/connection.js:453:17)
at TLSSocket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at TLSSocket.Readable.push (_stream_readable.js:213:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23) {
ok: 0,
errmsg: 'user is not allowed to do action [insert] on [fcc-mongodb-and-mongoose.people]',
code: 8000,
codeName: 'AtlasError',
[Symbol(mongoErrorContextSymbol)]: {}
}
This is the MONGO_URI secret environment variable (I copy/pasted from the mongodb connect to application link, and added the password and database name)
mongodb+srv://first-user2:passwordhere@cluster0.wvh0vkk.mongodb.net/fcc-mongodb-and-mongoose?retryWrites=true&w=majority
I wasn’t really sure what to do about the database name, and the only mention of it is right here in the environment variable. I created a collection named that in the cluster, but I’m not sure that’s right.
This is the code I added in the myApp.js file
mongoose.connect(process.env.MONGO_URI)
let personSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
age: {
type: Number
},
favoriteFoods: [{
type: String
}]
})
let Person = mongoose.model("Person", personSchema);
const createAndSavePerson = (done) => {
let bobo = new Person({name: "Bobo", age: 98, favoriteFoods: ["Pizza", "Laundry"]})
bobo.save((err, data) => {
if (err) return console.error(err)
done(null, data);
})
};
If anyone can help that would be great!