Problem on MongoDB and Mongoose - Create and Save a Record of a Model

i got error on “Mongodb Create and Save a Record of a Model challenge”.
// running tests

not authorized on admin to execute command { insert: “people”, documents: [[{favoriteFoods []} {_id ObjectIdHex(“5d17b9d57c1bf6007f2e2a7f”)} {name Ben} {age 23} {__v 0}]], ordered: true, lsid: { id: {4 [105 79 193 156 112 180 71 213 152 28 193 240 241 167 9 166]} }, $clusterTime: { clusterTime: 6708034412866437121, signature: { hash: [183 201 90 243 119 7 88 214 151 217 141 203 128 76 129 65 117 175 106 38], keyId: 6707589862276464640.000000 } }, $db: “admin” }

// tests completed

my code:

var Schema = mongoose.Schema;
var personSchema = new Schema({
  name: String,
  age: Number,
  height: Number,
  gender: String,
  favoriteFoods: [String]

var Person = mongoose.model('Person', personSchema);
var createAndSavePerson = function(done) {
 const person = new Person({name: 'Kieff', age: 33, favoriteFoods: ['fish', 'meat']}), data)=>{
  if (err) {
done(null, data)

Please Help. I feel the backend challenge instruction is very difficult to follow and not much resources could find out the answer :frowning:

anyone pass this challenge could pass some insight?

I can go ahead and take a look at it. I am going to start the section on my own glitch, but would you mind posting a link to your code?


Thanks in advance, cheers!

So I just Remixed your project. It did not have anything in the .envfile for MONGO_URI, which is the variable that is used to connect to the database. I am not sure if you forgot to add a MONGO_URI, or if glitch was just protecting your .env file. I added my own MONGO_URI and your code passed the tests. If you do not have aMONGO_URI set, you should go set that and it should pass. If you do have one set and it is still not working, or if you do not know how/where to get one, let me know and I will try to help out.

1 Like

Thanks, I do have the. env file. The Glitch protected it so it could be my password is wrong?
Do we change URI password? Is it included < password > ?
If my password is <abcd12! >, I rewrite it abcd12%(ascii). Is it correct?
Sorry for annoying you :slight_smile:

According to this link, only @, :, /, and % need to be encoded, so I would try and do it as abcd12!. If you can’t get it to work still, you can try changing the password so that it doesn’t contain any punctuation. If that doesn’t work let me know.

And please don’t feel like you’re bothering anybody on here. We’ve all been where you are, not being able to figure out some random error we barely understand. I came onto the forum this morning specifically to try and help people that were struggling with things that I can do fairly well, and I assume most posters do the same. We are here to help, because we know other people will help us if we need it.

1 Like

Thank you very much, You are awesome, will try it when I am home!
Very appreciate the help, hope I could do the same one day. Thanks for the motivation!

No problem, I hope that it helps. Like I said, reply to this again if you’re still having trouble.

And I hope you can do the same one day, too! In my experience, the programming community is very supportive and helpful. Don’t stop asking questions like this, they are what help you learn. Once you learn enough, you will be able to help people too. Right now, I’m sure you would be able to help if somebody new to programming asked you a simple HTML question. Maybe some simple CSS or Javascript too. Keep learning, and the list of topics you know well enough to help someone will keep growing.

Will do, Thanks!
Your help made me keep trying it :slight_smile:

Yeah! Finally i solved it.
There is connection problem with mongodb somehow on my side.
So i have to change

mongoose.connect('mongodb+srv://', { useNewUrlParser: true })

(i did the same last night but didnt work, might be the password was wrong at that time.
it spent me another 2hours to debug and looking for answer.
Hope it could help someone who have the same issue.

One thing I forgot, try putting the MONGO_URI in your process.env file in quotes. I don’t know why, and it tells you not to. I had a similar problem on these projects and I forgot about it. See if that works.

‘Hello sir;’
‘I had the same problem, I searched for two days found the solution, thank you very much.
until now I can not understand why the le docier .en does not allow me to add the url of mongodb Atlas.
thank you very much you saved me really’