MongoDB and Mongoose - Create and Save a Record of a Model

Tell us what’s happening:

Hi can any one help me with these chalenge, i have reed a lot of topics, serched and noting

Your code so far:

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

/** 1) Install & Set up mongoose */
const mongoose = require('mongoose');

/** 2) Create a person */
const Schema = mongoose.Schema;
const personSchema = new Schema({
  name: { type: String, required: true },
  age: Number,
  favoriteFoods: [String]
const Person = mongoose.model("Person", personSchema);

/** 3) Create and Save a Person */
const createAndSavePerson = (done) => {
  let dave= new Person({name: 'Dave', age:27, favoriteFoods:['pizza','chips']}),data) =>{

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

Challenge Information:

MongoDB and Mongoose - Create and Save a Record of a Model

The code you posted should pass. Make sure you didn’t remove the exports at the bottom of the file.

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;

How are you running it, from where, and did you use the boilerplate?

Tank you for the code I’ve already check my code and put the code you gave me but it dosen’t works it tells me this:

[Error: Cannot read properties of undefined (reading ‘modelName’)]

I’m runing it from repplit whit the green button “Run”, and sorry but i din’t understood the last part: “and did you use the boilerplate?”

Post the link to your Replit.

Yes there you have


That is not the code for the same challenge. You linked to the stock checker project, not the MongoDB and Mongoose challenge.

Oh sorry

You do not have the personSchema or Person model you created in the previous challenge.

You should have code like this before the createAndSavePerson function.

const PersonSchema = new Schema({
  name: {
    type: String,
    required: true
  age: {
    type: Number
  favoriteFoods: {
    type: [String]

const Person = mongoose.model("Person", PersonSchema);

I would strongly suggest you read the article that is linked to. The challenges do (unfortunately) not provide all that much information and I’m not surprised if it is a little confusing. The curriculum is pretty terse in this section.

I would look at YouTube and other articles on MongoDB and Mongoose as well.