MongoDB and Mongoose - Install and Set Up Mongoose

Authentication fail and call back(New Mongo Error)
I followed the instruction given in the curriculum webpage but the response is bad authentication and call back error.

My replit link

What is the new url parser and unified topology?

mongoose.connect(Your URI, { useNewUrlParser: true, useUnifiedTopology: true });

I added the following code in the myApps.js file

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36 OPR/

Challenge: MongoDB and Mongoose - Install and Set Up Mongoose

Link to the challenge:

It most likely means you didn’t use the correct username or password.

Make sure you didn’t add the <> part of the password placeholder you get with the connection string.

1 Like


Still cannot resolve the issue

  1. MongoParseError - incomplete key value pair for option at ParseQueryString

My replit link is as the following:```
2. Changed the mongoose version 5.11.15 but still unable to pass this level.

You’ve pasted your MONGO_URI into a string in your myApp.js file which means that your username and password are currently publicly visible.
I did notice that the end of the string is missing this however: =true&w=majority
I don’t know if you need to update your MONGO_URI variable?


I have updated the MONGO_URI string in the index.js file. The response remains the same.

I was given a link to clone a repo from github based in the curriculum instructions

The myApps.js consists of the following codes:


let Person;

const createAndSavePerson = (done) => {
  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;

If I add the Mongoose connect code after the dotenv code as in the followings, there are still some missing codes that I have to add for the

Let person statement?

/*  ================== */

/** 1) Install & Set up mongoose */
const mongoose = require("mongoose");
mongoose.connect(process.env['MONGO_URI'], { useNewUrlParser: true, useUnifiedTopology: true });

You still have your MONGO_URI publicly visible, now in your Index.js file. It should only be stored in your Secrets tab.

That said, I forked your repl and tested your MONGO_URI and it came back as ‘authentication failed’.

So there must be a problem with your username or password.

Ok, I will try to fix the error.

So my mistake was I didn’t read the instructions properly in the Mongodb Atlas page.

To connect using the process.env method is as the followings:

  1. Key in the script in my apps.js

  2. Use the secret tab to hide the URI code link. Use a variable to represent the value. And this URI code link have to add
    =true&w=majority at the end

  3. Use user password instead of login password which is autogenerated on the Database Access section.


One other thing to be aware of. If your username or password contains any of these special characters, you must use percent encoding in your URI: : / ? # [ ] @

More info here.

If you’re still stuck, make sure you’ve followed the setup instructions exactly (which are linked in the challenge description): MongoDB Atlas Tutorial – How to Get Started

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.