Install and Set Up Mongoose - "Using Replit"

Cannot fully install and set-up mongoose:
Describe your issue in detail here.
When i try to run on replit, the console shows error code “ELIFECYCLE” and “errno 1”
pointing to the name tag on package-JSON.
please see attached.

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36

Challenge: Install and Set Up Mongoose

Link to the challenge:

Can you share your replit link?

Thank you.
Please find attached.
.env
REDACTED

myApp

Package-lock json

Package Json

First off, you should never share the contents of your env file.

I just removed that.

That is sensitive information and it if gets into the wrong hands then people can mess with your app.

You never want to push that information to GitHub and you never want to share it publicly.

It is important that you learn that now instead of the hard way :grinning:

Secondly, it will be a lot more helpful if you share the replit link instead of screenshots.

That way I can test it on my end to see what is going on.

Thanks for your advice.
Regarding the replit link, couldn’t generate a specific link due to rejection at the console level.
Happy to adapt to your suggestion.

You should be able to share the link found at the top. I don’t think there should be any problems there

got you

You needed to scroll up and read the full error message

/home/runner/boilerplate-mongomongoose-11/myApp.js:14
let Person = mongoose.model('Person', peopleSchema);
    ^

SyntaxError: Identifier 'Person' has already been declared

Looking at your code you wrote this

let Person;

let peopleSchema = new mongoose.Schema({
  name : { type: String, required: true },
  age : Number,
  favoriteFoods : [String]
})

let Person = mongoose.model('Person', peopleSchema);

Also, make sure you are using the correct mongo db version from the instructions.
Add mongodb@~3.6.0 and mongoose@~5.4.0 to the project’s package.json .

When I make those changes I am able to pass the test.

Let me take these out and resend. The above were when i tried to bypass the error on the installation of mongoose.
The dependencies have the correct versions of ~3.6.0 and ~5.4.0

This is how it should read before initiating the codes above (Person Scheme)

Thanks

Once you add back in the schema, then the model then it should pass.

The mongodb@~3.6.0 and mongoose@~5.4.0 are already in the dependencies.
please see the below screenshot

mongodb is reading as 3.6.12 instead of 3.6.0

For these challenges, it is always best to use the exact version FCC wants you to since they wrote the tests.

I actually copied directly from the text. Surprise it shows ~3.6.12.

i just amended but same error message. i will probably start on a different topic and return at a later date.
Many thanks for your time.
Much appreciated

oops… I tested the wrong version of your code.

The new error message is this.

the options [useUnifiedTopology] is not supported
/home/runner/boilerplate-mongomongoose-12/myApp.js:68
exports.PersonModel = Person;
^

ReferenceError: Person is not defined
at Object. (/home/runner/boilerplate-mongomongoose-12/myApp.js:68:23)

This version works

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



let peopleSchema = new mongoose.Schema({
  name : { type: String, required: true },
  age : Number,
  favoriteFoods : [String]
})

let Person = mongoose.model('Person', peopleSchema);

I got excited briefly…
i will check at the Atlas end.
From the console, the error shows as:

I tested the wrong version of your code earlier.

You need to scroll up and read the full error message.

You deleted let Person but it is being exported at the end of your file.

You need to add that back in.

I will check that, but i think the error started during the process of installing mongoose.

Yeah the first error was because you defined Person twice.

You initially wrote this.

Then you deleted it completely instead of deleting just one of them.

I was able to pass with this

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



let peopleSchema = new mongoose.Schema({
  name : { type: String, required: true },
  age : Number,
  favoriteFoods : [String]
})

let Person = mongoose.model('Person', peopleSchema);

You still need Person in the file.
You just don’t need two of them.

Hopefully that is clearer now.