Bug in MongoDB and Mongoose Course

There appears to be a bug in " Create a Model" the second challenge in the MongoDB and Mongoose course in the Back End Development and APIs section.

The instructions for the challenge are:

Create a person schema called personSchema with the following shape:

  • A required name field of type String
  • An age field of type Number
  • A favouriteFoods field of type [String]

Use the Mongoose basic schema types. If you want you can also add more fields, use simple validators like required or unique, and set default values. See our Mongoose article.

Now, create a model from the personSchema and assign it to the existing variable Person.

If you note the British English spelling of the field “favouriteFoods”.

When you come to verify your solution to the challenge it posts the following form data to the path /api/mongoose-model/

name=Mike&age=28&favoriteFoods[]=pizza&favoriteFoods[]=cheese

If you note the US English spelling of the field “favoriteFoods”.

This means that if you follow the instructions and spell the field as instructed the spelling of the fields in the form data does not match the spelling of the fields in the model which means that the data doesn’t map to the model and the test fails.

For example, the following code fails when it should pass.

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

const personSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true
  },
  age: { type: Number },
  favouriteFoods: { type: [String] }
});

let Person = mongoose.model("Person", personSchema);

But the following code passes when it should fail:

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

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

let Person = mongoose.model("Person", personSchema);

To fix the spelling in the instructions could simply be changed to the US English spelling of “favorite”.

Thank you for taking the time to open this.

We are aware of this, and this has been fixed upstream, but has not been deployed yet: Conflicting English Dialect Usage in MongoDB & Mongoose Create a Model Makes Challenge Confusing · Issue #49677 · freeCodeCamp/freeCodeCamp · GitHub

Thanks, I wish I hadn’t spent all that time writing it out now but good to know it has already been fixed.

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