Please review my code

Tell us what’s happening:
unable to pass this test

Your code so far

        require('dotenv').config();


//let Person;

//const createAndSavePerson = (done) => {
  //done(null /*, data*/);
//};

//const createManyPeople = (arrayOfPeople, done) => {
 // done(null /*, data*/);
//};

//const findPeopleByName = (personName, done) => {
 // done(null /*, data*/);
//};
//01
const mongoose=require("mongoose");
let uri ='mongodb+srv://name:password@backendlessons.uoknb.mongodb.net/db1?retryWrites=true&w=majority'

mongoose.connect(process.env.MONGO_URI,{useNewUrlParse:true, useUnifiedTopology:true});
//02 create PersonModel
const Schema = mongoose.Schema;
var personSchema = new Schema({
  name:{type:String, required:true},
  age:Number,
  favoriteFoods:[String]
  
});
var Person = mongoose.model("Person", personSchema);



//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;

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; SM-A107F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.111 Mobile Safari/537.36.

Challenge: Create a Model

Link to the challenge:

I see that you have an unused variable uri with the connection string but then you pass process.env.MONGO_URI to mongoose.connect. In the .env file you should have

MONGO_URI=connection_string

and just delete the variable uri.

1 Like

ok. thanks. the MONGO_URI value to be written in the sample.env file right?

No, sample.env is meant to be used as documentation only as it will be committed to the repository. It will have all of the variables listed but with no values. .env is the actual name of the file that you use. It contains passcodes and keys that are meant to be kept private. We use this file so that private values don’t get hardcoded into the actual code. .env should be added to the file .gitignore so that it never gets committed. By the way, your passcode was listed in the posts above. I removed it, but it may have been seen by others, so you should change it to something else.