Freecodecamp mongoose

I’m trying to do the challenges in the backend devolepment section but the website doesnt accept my solutions. I checked the solutions in the ‘get a hint’ and tried them but it keeps saying 'tests failed. What do i do?

Ensure your code matches the challenge requirements precisely. Check for typos and syntax errors. If issues persist, seek community assistance.

Welcome there,

Without seeing your code/app, it is difficult to debug what could be preventing the tests from passing. Would you be able to share your code either by linking to a repository (e.g. GitHub) or an online IDE (e.g. Replit).

When those backend challenges don’t accept solutions, it’s a headache. Double-check your code, ensure it meets the challenge requirements, and watch for sneaky typos or formatting issues. If all looks good, reach out to the website support. It might be a glitch on their end.

oh of course these code dont passed challenges except the model.remove() one. thanks for your helps

var findOneByFood = function(food, done) {
  Person.findOne({favoriteFoods: food}, function (err, data) {
    if (err) return console.log(err);
    done(null, data);
  });
};

const findPersonById = (personId, done) => {
  Person.findById(personId, function(err, data){
    if (err) return console.log(err);
    done(null , data);
  });
};

const findEditThenSave = (personId, done) => {
  const foodToAdd = "hamburger";
  Person.findById(personId, function(err, person){
    if (err) return console.log(err);
    person.favoriteFoods.push(foodToAdd);
    person.save(function(err, updatedPerson){
      if (err) return console.log(err);
      done(null, updatedPerson);
    })
  })
};

const findAndUpdate = (personName, done) => {
  const ageToSet = 20;
  Person.findOneAndUpdate({name: personName}, {age: ageToSet}, {new: true}, (err, updatedDoc) =>{
      if (err) return console.log(err);
      done(null, updatedDoc);
    })
};

const removeById = (personId, done) => {
  Person.findOneAndRemove({_id: personId}, function(err, data){
    if(err) return console.log(err);
  done(null , data)
  });
};

const removeManyPeople = (done) => {
  const nameToRemove = "Mary";
  Person.remove( {name: nameToRemove}, function(err, data){
    if(err) return console.log(err);
    done(null, data);
  })
};

const queryChain = (done) => {
  const foodToSearch = "burrito";
  Person.find({favouriteFoods: foodToSearch})
  .sort({name: "asc"})
  .limit(2)
  .select({age: 0})
  .exec(function(err, data){
    done(error, data);
  });
};

https://boilerplate-mongomongoose-2.hzeynepk221.repl.co/ and this is the link for my solution

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